1 USING: help.markup help.syntax parser ;
4 ARTICLE: "vocabulary-search-shadow" "Shadowing word names"
5 "If adding a vocabulary to the search path results in a word in another vocabulary becoming inaccessible due to the new vocabulary defining a word with the same name, we say that the old word has been " { $emphasis "shadowed" } "."
7 "Here is an example where shadowing occurs:"
10 "USING: sequences io ;"
13 " \"foe::append calls sequences:append\" print append ;"
18 " \"fee::append calls fee:append\" print append ;"
24 " \"fox::append calls foe:append\" print append ;"
26 "\"1234\" \"5678\" append print"
29 "\"1234\" \"5678\" append print"
31 "When placed in a source file and run, the above code produces the following output:"
33 "foe:append calls sequences:append"
35 "fee:append calls foe:append"
36 "foe:append calls sequences:append"
40 ARTICLE: "vocabulary-search-errors" "Word lookup errors"
41 "If the parser cannot not find a word in the current vocabulary search path, it attempts to look for the word in all loaded vocabularies."
43 "If " { $link auto-use? } " mode is off, a restartable error is thrown with a restart for each vocabulary in question, together with a restart which defers the word in the current vocabulary, as if " { $link POSTPONE: DEFER: } " was used."
45 "If " { $link auto-use? } " mode is on and only one vocabulary has a word with this name, the vocabulary is added to the search path and parsing continues."
47 "If any restarts were invoked, or if " { $link auto-use? } " is on, the parser will print the correct " { $link POSTPONE: USING: } " after parsing completes. This form can be copy and pasted back into the source file."
48 { $subsection auto-use? } ;
50 ARTICLE: "vocabulary-search" "Vocabulary search path"
51 "When the parser reads a token, it attempts to look up a word named by that token. The lookup is performed by searching each vocabulary in the search path, in order."
53 "For a source file the vocabulary search path starts off with one vocabulary:"
55 "The " { $vocab-link "syntax" } " vocabulary consists of a set of parsing words for reading Factor data and defining new words."
57 "In the listener, the " { $vocab-link "scratchpad" } " is the default vocabulary for new word definitions. However, when loading source files, there is no default vocabulary. Defining words before declaring a vocabulary with " { $link POSTPONE: IN: } " results in an error."
59 "At the interactive listener, the default search path contains many more vocabularies. Details on the default search path and parser invocation are found in " { $link "parser" } "."
61 "Three parsing words deal with the vocabulary search path:"
62 { $subsection POSTPONE: IN: }
63 { $subsection POSTPONE: USE: }
64 { $subsection POSTPONE: USING: }
65 "There are some additional parsing words give more control over word lookup than is offered by " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } ":"
66 { $subsection POSTPONE: QUALIFIED: }
67 { $subsection POSTPONE: QUALIFIED-WITH: }
68 { $subsection POSTPONE: FROM: }
69 { $subsection POSTPONE: EXCLUDE: }
70 { $subsection POSTPONE: RENAME: }
71 "These words are useful when there is no way to avoid using two vocabularies with identical word names in the same source file."
73 "Private words can be defined; note that this is just a convention and they can be called from other vocabularies anyway:"
74 { $subsection POSTPONE: <PRIVATE }
75 { $subsection POSTPONE: PRIVATE> }
76 { $subsection "vocabulary-search-errors" }
77 { $subsection "vocabulary-search-shadow" }
78 { $see-also "words" } ;
80 ABOUT: "vocabulary-search"