]> gitweb.factorcode.org Git - factor.git/blob - core/vocabs/vocabs-docs.factor
git: fix tests
[factor.git] / core / vocabs / vocabs-docs.factor
1 USING: help.markup help.syntax strings words compiler.units
2 vocabs.loader assocs ;
3 IN: vocabs
4
5 ARTICLE: "vocabularies" "Vocabularies"
6 "A " { $emphasis "vocabulary" } " is a named collection of " { $link "words" } ". Vocabularies are defined in the " { $vocab-link "vocabs" } " vocabulary."
7 $nl
8 "Vocabularies are stored in a global hashtable:"
9 { $subsections dictionary }
10 "Vocabularies form a class."
11 { $subsections
12     vocab
13     vocab?
14 }
15 "Various vocabulary words are overloaded to accept a " { $emphasis "vocabulary specifier" } ", which is a string naming the vocabulary, the " { $link vocab } " instance itself, or a " { $link vocab-link } ":"
16 { $subsections
17     vocab-link
18     >vocab-link
19 }
20 "Looking up vocabularies by name:"
21 { $subsections vocab }
22 "Accessors for various vocabulary attributes:"
23 { $subsections
24     vocab-name
25     vocab-main
26     vocab-help
27 }
28 "Looking up existing vocabularies and creating new vocabularies:"
29 { $subsections
30     lookup-vocab
31     loaded-child-vocab-names
32     create-vocab
33 }
34 "Getting words from a vocabulary:"
35 { $subsections
36     vocab-words-assoc
37     vocab-words
38     all-words
39     words-named
40 }
41 "Removing a vocabulary:"
42 { $subsections forget-vocab }
43 { $see-also "words" "vocabs.loader" "word-search" } ;
44
45 ABOUT: "vocabularies"
46
47 HELP: dictionary
48 { $var-description "Holds a hashtable mapping vocabulary names to vocabularies." } ;
49
50 HELP: loaded-vocab-names
51 { $values { "seq" { $sequence string } } }
52 { $description "Outputs a sequence of all defined vocabulary names." } ;
53
54 HELP: lookup-vocab
55 { $values { "vocab-spec" "a vocabulary specifier" } { "vocab" vocab } }
56 { $description "Outputs a named vocabulary, or " { $link f } " if no vocabulary with this name exists." } ;
57
58 HELP: vocab
59 { $class-description "Instances represent vocabularies." } ;
60
61 HELP: vocab-name
62 { $values { "vocab-spec" "a vocabulary specifier" } { "name" string } }
63 { $description "Outputs the name of a vocabulary." } ;
64
65 HELP: vocab-words-assoc
66 { $values { "vocab-spec" "a vocabulary specifier" } { "assoc/f" { $maybe assoc } } }
67 { $description "Outputs the words defined in a vocabulary." } ;
68
69 HELP: vocab-words
70 { $values { "vocab-spec" vocab-spec } { "seq" { $sequence word } } }
71 { $description "Outputs a sequence of words defined in the vocabulary, or " { $link f } " if no vocabulary with this name exists." } ;
72
73 HELP: all-words
74 { $values { "seq" { $sequence word } } }
75 { $description "Outputs a sequence of all words in the dictionary." } ;
76
77 HELP: forget-vocab
78 { $values { "vocab" string } }
79 { $description "Removes a vocabulary. All words in the vocabulary are forgotten." }
80 { $notes "This word must be called from inside " { $link with-compilation-unit } "." } ;
81
82 HELP: require-hook
83 { $var-description { $quotation ( name -- ) } " which loads a vocabulary. This quotation is called by " { $link require } ". The default value should not need to be changed; this functionality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
84
85 HELP: require
86 { $values { "object" "a vocabulary specifier" } }
87 { $description "Loads a vocabulary if it has not already been loaded. Throws an error if the vocabulary does not exist on disk or in the dictionary." }
88 { $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
89
90 HELP: words-named
91 { $values { "str" string } { "seq" { $sequence word } } }
92 { $description "Outputs a sequence of all words named " { $snippet "str" } " from the set of currently-loaded vocabularies." } ;
93
94 HELP: create-vocab
95 { $values { "name" string } { "vocab" vocab } }
96 { $description "Creates a new vocabulary if one does not exist with the given name, otherwise outputs an existing vocabulary." } ;
97
98 HELP: loaded-child-vocab-names
99 { $values { "vocab-spec" "a vocabulary specifier" } { "seq" { $sequence string } } }
100 { $description "Outputs all vocabularies which are conceptually under " { $snippet "vocab" } " in the hierarchy." }
101 { $examples
102     { $unchecked-example
103         "\"io.streams\" loaded-child-vocab-names ."
104         "{ \"io.streams.c\" \"io.streams.duplex\" \"io.streams.lines\" \"io.streams.nested\" \"io.streams.plain\" \"io.streams.string\" }"
105     }
106 } ;
107
108 HELP: vocab-link
109 { $class-description "Instances of this class identify vocabularies which are potentially not loaded. The " { $link vocab-name } " slot is the vocabulary name."
110 $nl
111 "Vocabulary links are created by calling " { $link >vocab-link } "."
112 } ;
113
114 HELP: >vocab-link
115 { $values { "name" string } { "vocab" "a vocabulary specifier" } }
116 { $description "If the vocabulary is loaded, outputs the corresponding " { $link vocab } " instance, otherwise creates a new " { $link vocab-link } "." } ;
117
118 HELP: runnable-vocab
119 { $class-description "The class of vocabularies with a " { $slot "main" } " word." } ;