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
|
2005-12-17 09:55:00 -05:00
|
|
|
USING: errors hashtables kernel lists namespaces sequences
|
|
|
|
|
strings ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2005-09-16 02:39:33 -04:00
|
|
|
SYMBOL: bootstrapping?
|
|
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
SYMBOL: vocabularies
|
|
|
|
|
|
2005-08-25 15:27:38 -04:00
|
|
|
: word ( -- word ) \ word global hash ;
|
2006-01-06 02:04:42 -05:00
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
: set-word ( word -- ) \ word set-global ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: vocabs ( -- seq ) vocabularies get hash-keys string-sort ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: vocab ( name -- vocab ) vocabularies get hash ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: ensure-vocab ( name -- ) vocabularies get [ nest drop ] bind ;
|
2005-12-17 09:55:00 -05:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: words ( vocab -- list ) vocab dup [ hash-values ] when ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: all-words ( -- list ) vocabs [ words ] map concat ;
|
2005-04-10 18:58:30 -04:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: each-word ( quot -- ) all-words swap each ; inline
|
2005-04-10 18:58:30 -04:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: word-subset ( pred -- list )
|
2005-08-25 15:27:38 -04:00
|
|
|
all-words swap subset ; 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-08-25 15:27:38 -04:00
|
|
|
all-words swap subset-with ; inline
|
2005-04-12 13:35:27 -04:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: recrossref ( -- )
|
2005-12-13 17:33:58 -05:00
|
|
|
crossref get clear-hash [ add-crossref ] each-word ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-22 20:54:01 -04:00
|
|
|
: lookup ( name vocab -- word ) vocab ?hash ;
|
|
|
|
|
|
2004-10-17 19:01:16 -04:00
|
|
|
: reveal ( word -- )
|
2004-12-15 16:57:29 -05:00
|
|
|
vocabularies get [
|
2005-07-23 01:03:46 -04:00
|
|
|
dup word-name over word-vocabulary nest set-hash
|
2004-10-17 19:01:16 -04:00
|
|
|
] bind ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-08-21 23:35:50 -04:00
|
|
|
: check-create ( name vocab -- )
|
|
|
|
|
string? [ "Vocabulary name is not a string" throw ] unless
|
|
|
|
|
string? [ "Word name is not a string" throw ] unless ;
|
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
: create ( name vocab -- word )
|
2005-08-29 02:34:04 -04:00
|
|
|
2dup check-create 2dup lookup dup
|
2005-11-27 17:45:48 -05:00
|
|
|
[ 2nip ] [ drop <word> dup init-word dup reveal ] if ;
|
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 -- )
|
2005-05-02 00:18:34 -04:00
|
|
|
dup uncrossref
|
2005-10-04 03:16:50 -04:00
|
|
|
crossref get [ dupd remove-hash ] when*
|
2005-08-25 15:27:38 -04:00
|
|
|
dup word-name swap word-vocabulary vocab remove-hash ;
|
2004-12-15 16:57:29 -05:00
|
|
|
|
2005-11-27 17:45:48 -05:00
|
|
|
: target-word ( word -- word )
|
|
|
|
|
dup word-name swap word-vocabulary lookup ;
|
|
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: interned? ( word -- ? ) dup target-word eq? ;
|
2005-07-19 04:23:33 -04:00
|
|
|
|
2005-11-24 19:02:20 -05:00
|
|
|
: bootstrap-word ( word -- word )
|
2005-09-16 02:39:33 -04:00
|
|
|
dup word-name swap word-vocabulary
|
|
|
|
|
bootstrapping? get [
|
|
|
|
|
dup "syntax" = [ drop "!syntax" ] when
|
|
|
|
|
] when lookup ;
|