Next: User-defined compile-comma, Previous: Advanced does> usage example, Up: User-defined Defining Words
Gforth allows you to change the (to) action of a word.
(to) ( val xt – ) gforth-1.0 “paren-to”
xt is of a value like word name. Stores val to name.
doc-set-to
(to) is a word used inside to: it stores the value at
run-time. The general stack effect of (to) method is (
val xt -- ), where xt identifies the word stored into, and
val is the value (of appropriate type) stored there.
E.g., one can implement fvalue as follows:
: fvalue-to ( r xt -- )
>body f! ;
: fvalue ( r "name" -- ; name: -- r )
create f,
['] f@ set-does>
['] fvalue-to set-to ;
5e fvalue foo
: bar foo 1e f+ to foo ;
see bar
(To) is also known as defer! (called by is,
see Deferred Words), so you can use it to implement variations of
deferred words. You also need to change defer@ then, and you
can do that, too:
doc-set-defer