2005-01-29 14:18:28 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-07-19 04:23:33 -04:00
|
|
|
IN: words
|
|
|
|
|
USING: hashtables kernel lists namespaces strings sequences ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
SYMBOL: vocabularies
|
|
|
|
|
|
2004-12-15 16:57:29 -05:00
|
|
|
: word ( -- word ) global [ "last-word" get ] bind ;
|
|
|
|
|
: set-word ( word -- ) global [ "last-word" set ] bind ;
|
|
|
|
|
|
|
|
|
|
: vocabs ( -- list )
|
|
|
|
|
#! Push a list of vocabularies.
|
2005-07-19 04:23:33 -04:00
|
|
|
vocabularies get hash-keys [ lexi> ] sort ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
|
|
|
|
: vocab ( name -- vocab )
|
|
|
|
|
#! Get a vocabulary.
|
|
|
|
|
vocabularies get hash ;
|
|
|
|
|
|
|
|
|
|
: words ( vocab -- list )
|
|
|
|
|
#! Push a list of all words in a vocabulary.
|
|
|
|
|
#! Filter empty slots.
|
2004-12-25 18:08:20 -05:00
|
|
|
vocab dup [ hash-values [ ] subset word-sort ] when ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2005-04-10 18:58:30 -04:00
|
|
|
: all-words ( -- list )
|
2005-04-16 00:23:27 -04:00
|
|
|
[ vocabs [ words % ] each ] make-list ;
|
2005-04-10 18:58:30 -04:00
|
|
|
|
2004-12-15 16:57:29 -05:00
|
|
|
: each-word ( quot -- )
|
|
|
|
|
#! Apply a quotation to each word in the image.
|
2005-04-10 18:58:30 -04:00
|
|
|
all-words swap each ; inline
|
|
|
|
|
|
|
|
|
|
: word-subset ( pred -- list | pred: word -- ? )
|
|
|
|
|
#! A list of words matching the predicate.
|
2005-04-22 00:22:36 -04:00
|
|
|
all-words swap subset word-sort ; inline
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-04-12 13:35:27 -04:00
|
|
|
: word-subset-with ( obj pred -- list | pred: obj word -- ? )
|
2005-07-23 00:56:59 -04:00
|
|
|
all-words swap subset-with word-sort ; inline
|
2005-04-12 13:35:27 -04:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: recrossref ( -- )
|
|
|
|
|
#! Update word cross referencing information.
|
2005-05-15 21:17:56 -04:00
|
|
|
global [ <namespace> crossref set ] bind
|
2005-03-26 20:12:14 -05:00
|
|
|
[ add-crossref ] each-word ;
|
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
: search ( name list -- word )
|
|
|
|
|
#! Search for a word in a list of vocabularies.
|
|
|
|
|
dup [
|
2005-07-23 00:56:59 -04:00
|
|
|
2dup car vocab ?hash [ nip ] [ cdr search ] ?ifte
|
2004-07-16 02:26:21 -04:00
|
|
|
] [
|
2005-01-02 23:57:54 -05:00
|
|
|
2drop f
|
2004-07-16 02:26:21 -04:00
|
|
|
] ifte ;
|
|
|
|
|
|
2005-01-28 23:55:22 -05:00
|
|
|
: <props> ( name vocab -- plist )
|
|
|
|
|
"vocabulary" swons swap "name" swons 2list alist>hash ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
|
: (create) ( name vocab -- word )
|
2004-10-17 16:04:49 -04:00
|
|
|
#! Create an undefined word without adding to a vocabulary.
|
2005-01-28 23:55:22 -05:00
|
|
|
<props> <word> [ set-word-props ] keep ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-10-17 19:01:16 -04:00
|
|
|
: reveal ( word -- )
|
|
|
|
|
#! Add a new word to its vocabulary.
|
2004-12-15 16:57:29 -05:00
|
|
|
vocabularies get [
|
2004-12-24 02:52:02 -05:00
|
|
|
dup word-vocabulary nest [
|
|
|
|
|
dup word-name set
|
|
|
|
|
] bind
|
2004-10-17 19:01:16 -04:00
|
|
|
] bind ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
|
: create ( name vocab -- word )
|
|
|
|
|
#! Create a new word in a vocabulary. If the vocabulary
|
|
|
|
|
#! already contains the word, the existing instance is
|
|
|
|
|
#! returned.
|
2005-07-23 00:56:59 -04:00
|
|
|
2dup vocab ?hash [
|
2005-02-09 22:35:11 -05:00
|
|
|
nip
|
2005-03-05 14:45:23 -05:00
|
|
|
dup f "documentation" set-word-prop
|
|
|
|
|
dup f "stack-effect" set-word-prop
|
2005-02-09 22:35:11 -05:00
|
|
|
] [
|
|
|
|
|
(create) dup reveal
|
|
|
|
|
] ?ifte ;
|
2004-11-26 22:23:57 -05:00
|
|
|
|
2005-05-04 22:34:55 -04:00
|
|
|
: constructor-word ( string vocab -- word )
|
|
|
|
|
>r "<" swap ">" append3 r> create ;
|
|
|
|
|
|
2004-11-26 22:23:57 -05:00
|
|
|
: forget ( word -- )
|
|
|
|
|
#! Remove a word definition.
|
2005-05-02 00:18:34 -04:00
|
|
|
dup uncrossref
|
2004-11-26 22:23:57 -05:00
|
|
|
dup word-vocabulary vocab [ word-name off ] bind ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2005-07-19 04:23:33 -04:00
|
|
|
: 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 ;
|
|
|
|
|
|
2004-12-15 16:57:29 -05:00
|
|
|
: init-search-path ( -- )
|
|
|
|
|
! For files
|
|
|
|
|
"scratchpad" "file-in" set
|
2004-12-25 18:08:20 -05:00
|
|
|
[ "syntax" "scratchpad" ] "file-use" set
|
2004-12-15 16:57:29 -05:00
|
|
|
! For interactive
|
|
|
|
|
"scratchpad" "in" set
|
|
|
|
|
[
|
2005-07-19 17:56:22 -04:00
|
|
|
"compiler" "errors" "gadgets" "generic"
|
|
|
|
|
"hashtables" "help" "inference" "inspector" "interpreter"
|
2005-07-06 01:57:58 -04:00
|
|
|
"jedit" "kernel" "listener" "lists" "math" "matrices"
|
2005-07-19 17:56:22 -04:00
|
|
|
"memory" "namespaces" "parser" "prettyprint"
|
2005-06-27 03:47:22 -04:00
|
|
|
"sequences" "io" "strings" "styles" "syntax" "test"
|
|
|
|
|
"threads" "unparser" "vectors" "words" "scratchpad"
|
2004-12-15 16:57:29 -05:00
|
|
|
] "use" set ;
|