] with-compilation-unit
[ ] [ [ "vocabs.loader.test.j" require ] [ drop :1 ] recover ] unit-test
+
+[ ] [ "vocabs.loader.test.m" require ] unit-test
+[ f ] [ "vocabs.loader.test.n" vocab ] unit-test
+[ ] [ "vocabs.loader.test.o" require ] unit-test
+[ t ] [ "vocabs.loader.test.n" vocab >boolean ] unit-test
+
+[
+ "mno" [ "vocabs.loader.test." swap suffix forget-vocab ] each
+] with-compilation-unit
+
+[ ] [ "vocabs.loader.test.o" require ] unit-test
+[ f ] [ "vocabs.loader.test.n" vocab ] unit-test
+[ ] [ "vocabs.loader.test.m" require ] unit-test
+[ t ] [ "vocabs.loader.test.n" vocab >boolean ] unit-test
+
+[
+ "mno" [ "vocabs.loader.test." swap suffix forget-vocab ] each
+] with-compilation-unit
check-vocab-hook [ [ drop ] ] initialize
+DEFER: require
+
<PRIVATE
+: load-conditional-requires ( vocab-name -- )
+ conditional-requires get
+ [ at [ require ] each ]
+ [ delete-at ] 2bi ;
+
: load-source ( vocab -- )
dup check-vocab-hook get call( vocab -- )
[
dup vocab-source-path [ parse-file ] [ [ ] ] if*
[ +parsing+ >>source-loaded? ] dip
[ % ] [ call( -- ) ] if-bootstrapping
- +done+ >>source-loaded? drop
+ +done+ >>source-loaded?
+ vocab-name load-conditional-requires
] [ ] [ f >>source-loaded? ] cleanup ;
: load-docs ( vocab -- )
: require ( vocab -- )
load-vocab drop ;
+: require-if ( if then -- )
+ over vocab
+ [ nip require ]
+ [ swap conditional-requires get [ swap suffix ] change-at ]
+ if ;
+
: reload ( name -- )
dup vocab
[ [ load-source ] [ load-docs ] bi ]
--- /dev/null
+USE: vocabs.loader
+IN: vocabs.loader.test.m
+
+"vocabs.loader.test.o" "vocabs.loader.test.n" require-if
--- /dev/null
+IN: vocabs.loader.test.n
--- /dev/null
+IN: vocabs.loader.test.o
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs strings kernel sorting namespaces
-sequences definitions ;
+sequences definitions sets ;
IN: vocabs
SYMBOL: dictionary
: check-vocab-name ( name -- name )
dup string? [ bad-vocab-name ] unless ;
+SYMBOL: conditional-requires
+conditional-requires [ H{ } clone ] initialize
+
: create-vocab ( name -- vocab )
check-vocab-name
dictionary get [ <vocab> ] cache
M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
: forget-vocab ( vocab -- )
- dup words forget-all
- vocab-name dictionary get delete-at
+ [ words forget-all ]
+ [ vocab-name dictionary get delete-at ] bi
notify-vocab-observers ;
M: vocab-spec forget* forget-vocab ;