SYMBOL: vocabularies
-: word ( -- word ) global [ "last-word" get ] bind ;
-: set-word ( word -- ) global [ "last-word" set ] bind ;
+: word ( -- word ) "last-word" global hash ;
+: set-word ( word -- ) "last-word" global set-hash ;
: vocabs ( -- list )
#! Push a list of vocabularies.
vocab dup [ hash-values [ ] subset word-sort ] when ;
: all-words ( -- list )
- [ vocabs [ words % ] each ] make-list ;
+ vocabs [ words ] map concat ;
: each-word ( quot -- )
#! Apply a quotation to each word in the image.
global [ <namespace> crossref set ] bind
[ add-crossref ] each-word ;
-: search ( name list -- word )
- #! Search for a word in a list of vocabularies.
- dup [
- 2dup car vocab ?hash [ nip ] [ cdr search ] ?ifte
- ] [
- 2drop f
- ] ifte ;
+: search ( name vocabs -- word )
+ [ vocab ?hash ] map-with [ ] find nip ;
: <props> ( name vocab -- plist )
- "vocabulary" swons swap "name" swons 2list alist>hash ;
+ <namespace> [ "vocabulary" set "name" set ] extend ;
: (create) ( name vocab -- word )
#! Create an undefined word without adding to a vocabulary.
: reveal ( word -- )
#! Add a new word to its vocabulary.
vocabularies get [
- dup word-vocabulary nest [
- dup word-name set
- ] bind
+ dup word-name over word-vocabulary nest set-hash
] bind ;
: create ( name vocab -- word )
: interned? ( word -- ? )
#! Test if the word is a member of its vocabulary.
- dup dup word-name swap word-vocabulary dup [
- vocab dup [ hash eq? ] [ 3drop f ] ifte
- ] [
- 3drop f
- ] ifte ;
+ dup word-name over word-vocabulary vocab ?hash eq? ;
: init-search-path ( -- )
! For files