1 USING: vocabs vocabs.loader.private help.markup help.syntax
2 words strings io hashtables ;
5 ARTICLE: "add-vocab-roots" "Working with code outside of the Factor source tree"
6 "You can work with code outside of the Factor source tree by adding additional directories to the list of vocabulary roots."
8 "There are three ways of doing this."
10 "The first way is to use an environment variable. Factor looks at the " { $snippet "FACTOR_ROOTS" } " environment variable for a list of " { $snippet ":" } "-separated paths (on Unix) or a list of " { $snippet ";" } "-separated paths (on Windows)."
12 "The second way is to create a configuration file. You can list additional vocabulary roots in a file that Factor reads at startup:"
13 { $subsections ".factor-roots" }
14 "Finally, you can add vocabulary roots by calling a word from your " { $snippet ".factor-rc" } " file (see " { $link ".factor-rc" } "):"
15 { $subsections add-vocab-root } ;
17 ARTICLE: "vocabs.roots" "Vocabulary roots"
18 "The vocabulary loader searches for vocabularies in one of the root directories:"
19 { $subsections vocab-roots }
20 "The default set of roots includes the following directories in the Factor source directory:"
22 { { $snippet "core" } " - essential system vocabularies such as " { $vocab-link "parser" } " and " { $vocab-link "sequences" } ". The vocabularies in this root constitute the boot image; see " { $link "bootstrap.image" } "." }
23 { { $snippet "basis" } " - useful libraries and tools, such as " { $vocab-link "compiler" } ", " { $vocab-link "ui" } ", " { $vocab-link "calendar" } ", and so on." }
24 { { $snippet "extra" } " - additional contributed libraries." }
25 { { $snippet "work" } " - a root for vocabularies which are not intended to be contributed back to Factor." }
27 "You can store your own vocabularies in the " { $snippet "work" } " directory."
28 { $subsections "add-vocab-roots" } ;
30 ARTICLE: "vocabs.icons" "Vocabulary icons"
31 "An icon file representing the vocabulary can be provided for use by " { $link "tools.deploy" } ". If any of the following files exist inside the vocabulary directory, they will be used as icons when the application is deployed."
33 { { $snippet "icon.ico" } " on Windows and Linux" }
34 { { $snippet "icon.icns" } " on MacOS X" }
35 { { $snippet "icon.png" } " on Linux" }
37 "The icon file will be embedded in the vocab's image file." ;
39 ARTICLE: "vocabs.loader" "Vocabulary loader"
40 "The " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " words load vocabularies using the vocabulary loader. The vocabulary loader is implemented in the " { $vocab-link "vocabs.loader" } " vocabulary."
42 "The vocabulary loader searches for vocabularies in a set of directories known as vocabulary roots."
43 { $subsections "vocabs.roots" }
44 "Vocabulary names map directly to source files inside these roots. A vocabulary named " { $snippet "foo.bar" } " is defined in " { $snippet "foo/bar/bar.factor" } "; that is, a source file named " { $snippet "bar.factor" } " within a " { $snippet "bar" } " directory nested inside a " { $snippet "foo" } " directory of a vocabulary root. Any level of nesting, separated by dots, is permitted."
46 "The vocabulary directory - " { $snippet "bar" } " in our example - contains a source file:"
48 { { $snippet "foo/bar/bar.factor" } " - the source file must define words in the " { $snippet "foo.bar" } " vocabulary with an " { $snippet "IN: foo.bar" } " form" }
50 "Two other Factor source files, storing documentation and tests, respectively, may optionally be placed alongside the source file:"
52 { { $snippet "foo/bar/bar-docs.factor" } " - documentation, see " { $link "writing-help" } }
53 { { $snippet "foo/bar/bar-tests.factor" } " - unit tests, see " { $link "tools.test" } }
55 "Optional text files may contain metadata."
56 { $subsections "vocabs.metadata" "vocabs.icons" }
57 "Vocabularies can also be loaded at run time, without altering the vocabulary search path. This is done by calling a word which loads a vocabulary if it is not in the image, doing nothing if it is:"
58 { $subsections require }
59 "The above word will only ever load a vocabulary once in a given session. Sometimes, two vocabularies require special code to interact. The following word is used to load one vocabulary when another is present:"
60 { $subsections require-when }
61 "There is another word which unconditionally loads vocabulary from disk, regardless of whether or not is has already been loaded:"
62 { $subsections reload }
63 "For interactive development in the listener, calling " { $link reload } " directly is usually not necessary, since a better facility exists for " { $link "vocabs.refresh" } "."
65 "Application vocabularies can define a main entry point, giving the user a convenient way to run the application:"
71 { $see-also "vocabularies" "parser" "source-files" } ;
73 ABOUT: "vocabs.loader"
76 { $values { "name" "a string" } { "vocab" { $maybe hashtable } } }
77 { $description "Attempts to load a vocabulary from disk, or looks up the vocabulary in the dictionary, and then outputs that vocabulary object." } ;
80 { $values { "vocab-spec" "a vocabulary specifier" } { "main" word } }
81 { $description "Outputs the main entry point for a vocabulary. The entry point can be executed with " { $link run } " and set with " { $link POSTPONE: MAIN: } "." } ;
84 { $var-description "A sequence of pathname strings to search for vocabularies." } ;
87 { $values { "root" "a pathname string" } }
88 { $description "Adds a directory pathname to the list of vocabulary roots." }
89 { $see-also ".factor-roots" add-vocab-root-hook } ;
91 HELP: add-vocab-root-hook
92 { $var-description "A quotation that is run when a vocab root is added." }
93 { $see-also add-vocab-root } ;
96 { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } }
97 { $description "Searches for a vocabulary in the vocabulary roots." } ;
100 { $values { "name" "a vocabulary name" } }
101 { $description "A " { $link no-vocab } " error tuple. Call " { $link no-vocab } " to throw it." }
102 { $error-description "Thrown when a " { $link POSTPONE: USE: } " or " { $link POSTPONE: USING: } " form refers to a non-existent vocabulary." } ;
105 { $var-description "If set to a true value, documentation will be automatically loaded when vocabularies are loaded. This variable is usually on, except when Factor has been bootstrapped without the help system." } ;
108 { $values { "vocab" "a vocabulary specifier" } }
109 { $description "Loads a vocabulary's source code." } ;
112 { $values { "vocab" "a vocabulary specifier" } }
113 { $description "If " { $link load-help? } " is on, loads a vocabulary's documentation." } ;
116 { $values { "name" "a vocabulary name" } }
117 { $description "Reloads the source code and documentation for a vocabulary." }
118 { $errors "Throws a " { $link no-vocab } " error if the vocabulary does not exist on disk." } ;
121 { $values { "if" { $sequence "vocabulary specifiers" } } { "then" "a vocabulary specifier" } }
122 { $description "Loads the " { $snippet "then" } " vocabulary if it is not loaded and all of the " { $snippet "if" } " vocabulary is. If some of the " { $snippet "if" } " vocabularies are not loaded now, but they are later, then the " { $snippet "then" } " vocabulary will be loaded along with the final one." }
123 { $notes "This is used to express a joint dependency of vocabularies. If vocabularies " { $snippet "a" } " and " { $snippet "b" } " use code in vocabulary " { $snippet "c" } " to interact, then the following line, which can be placed in " { $snippet "a" } " or " { $snippet "b" } ", expresses the dependency."
124 { $code "{ \"a\" \"b\" } \"c\" require-when" } } ;
127 { $values { "vocab" "a vocabulary specifier" } }
128 { $description "Runs a vocabulary's main entry point. The main entry point is set with the " { $link POSTPONE: MAIN: } " parsing word." } ;
130 HELP: vocab-source-path
131 { $values { "vocab" "a vocabulary specifier" } { "path/f" { $maybe "a pathname string" } } }
132 { $description "Outputs a pathname where source code for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a known directory on disk." } ;
134 HELP: vocab-docs-path
135 { $values { "vocab" "a vocabulary specifier" } { "path/f" { $maybe "a pathname string" } } }
136 { $description "Outputs a pathname where the documentation for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a directory on disk." } ;