1) syntax for creation
2) syntax for adding to list of active vocabularies
3) syntax for setting up a list of vocabularies
4) how many *active* vocabularies should be allowed
Any input here will be appreciated. Thanks in advance,
-- crc
{{
variable current
: get-voc ' current ! ;
: set-current current @ @ last ! ;
: update last @ current @ ! [ ' ok 2 + compile ] ;
: parent current @ last @ ;
: child last ! current ! ;
: action ' execute ;
---reveal---
: use get-voc set-current ;
: voc create last @ , ;
: in parent push push use action pop pop child ;
voc core use core
' update is ok
}}
Then:
voc test-0
use test-0
: a 1 . ;
voc test-1
use test-1
: a 2 . ;
use test-0
: b 2 . ;
in test-1 a
a
use test-1
in test-0 b
use core
in test-0 in test-1 a
-- crc
Words Provided:
voc
Description: Create a vocabulary.
Usage:
voc name
use
Description: Make a vocabulary active
Usage:
use name
use|
Description: Activate a vocabulary, allows easier access to nested vocabularies.
Usage:
use| parent child0 child1 ... |
Notes: In this example, child1 is a vocabulary within child0 which is
itself inside parent.
in
Description: Access a word inside another vocabulary
Usage:
in name word
Notes: "in" can be nested:
in parent in child word
Now for the actual code:
{{
variable current
: activate current @ @ last ! ;
: update last @ current @ ! [ ' ok 2 + compile ] ;
: save current @ last @ ;
: restore last ! current ! ;
: action ' 0; which @ d->class @ with-class ;
---reveal---
: use ' 0; current ! activate ;
: use| repeat ' 0; current ! activate again ;
: voc create last @ , ;
macro: in save push push use action pop pop restore ;
voc core use core
' update is ok
}}
This has the original Retro wordset accessible via "use core".
Note for those using low-level hooks:
This code replaces the original prompt ("ok") with a new one that
keeps the vocabulary up to date with changes to the dictionary. You
would need to account for this if your code replaces "ok" with
something else.
-- crc