]> gitweb.factorcode.org Git - factor.git/commitdiff
Make the require-hook throw an error if the vocabulary does not exist in the dictiona...
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 3 Nov 2011 18:34:41 +0000 (11:34 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 3 Nov 2011 18:39:34 +0000 (11:39 -0700)
core/vocabs/loader/loader-docs.factor
core/vocabs/loader/loader.factor
core/vocabs/vocabs-docs.factor
core/vocabs/vocabs-tests.factor

index 8a0a346a1b5a8cb7d28f63989db27f4530fcd46f..f50bdd6d0de48037fe646a76194fc545da6177b2 100755 (executable)
@@ -73,8 +73,7 @@ ABOUT: "vocabs.loader"
 
 HELP: load-vocab
 { $values { "name" "a string" } { "vocab" "a hashtable or " { $link f } } }
-{ $description "Outputs a named vocabulary. If the vocabulary does not exist, throws a restartable " { $link no-vocab } " error. If the user invokes the restart, this word outputs " { $link f } "." }
-{ $error-description "Thrown by " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " when a given vocabulary does not exist. Vocabularies must be created by " { $link POSTPONE: IN: } " before being used." } ;
+{ $description "Attempts to load a vocabulary from disk, or looks up the vocabulary in the dictionary, and then outputs that vocabulary object." } ;
 
 HELP: vocab-main
 { $values { "vocab-spec" "a vocabulary specifier" } { "main" word } }
@@ -113,11 +112,6 @@ HELP: reload
 { $description "Reloads the source code and documentation for a vocabulary." }
 { $errors "Throws a " { $link no-vocab } " error if the vocabulary does not exist on disk." } ;
 
-HELP: require
-{ $values { "vocab" "a vocabulary specifier" } }
-{ $description "Loads a vocabulary if it has not already been loaded." }
-{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
-
 HELP: require-when
 { $values { "if" "a sequence of vocabulary specifiers" } { "then" "a vocabulary specifier" } }
 { $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." }
index 37118590944a44084138873076b62334785ccf9d..56866fca01cc598018884f2dbf9f04578e91c072 100644 (file)
@@ -159,8 +159,12 @@ PRIVATE>
 [
     dup vocab-name blacklist get at*
     [ rethrow ]
-    [ drop dup find-vocab-root [ (require) ] [ drop ] if ]
-    if
+    [
+        drop dup find-vocab-root
+        [ (require) ]
+        [ dup lookup-vocab [ drop ] [ no-vocab ] if ]
+        if
+    ] if
 ] require-hook set-global
 
 M: vocab-spec where vocab-source-path dup [ 1 2array ] when ;
index 301b4b838b645ae2f484f3f8ce1f8dea40b03c1c..64101dc6d64bc33abe8398a7b84a80d58853e883 100644 (file)
@@ -1,4 +1,5 @@
-USING: help.markup help.syntax strings words compiler.units ;
+USING: help.markup help.syntax strings words compiler.units
+vocabs.loader ;
 IN: vocabs
 
 ARTICLE: "vocabularies" "Vocabularies"
@@ -79,6 +80,11 @@ HELP: forget-vocab
 HELP: require-hook
 { $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" } "." } ;
 
+HELP: require
+{ $values { "object" "a vocabulary specifier" } }
+{ $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." }
+{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
+
 HELP: words-named
 { $values { "str" string } { "seq" "a sequence of words" } }
 { $description "Outputs a sequence of all words named " { $snippet "str" } " from the set of currently-loaded vocabularies." } ;
index a7421b89c9b8ce243d667f5037078556c7fe1848..6ed0594be66227ed8863a299543c661ac5726924 100644 (file)
@@ -29,3 +29,9 @@ IN: vocabs.tests
 [ 3 >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
 [ f >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
 [ "a b" >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+
+[ "sojoijsaoifjsthisdoesntexistomgomgomgplznodontexist" require ]
+[ no-vocab? ] must-fail-with
+
+[ "letstrythisagainnooooooyoucantexistnoooooo" load-vocab ]
+[ no-vocab? ] must-fail-with