mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
320e100737
FossilOrigin-Name: deab79dff5f0c935a74469f50ab8b04f557dcfe0da623d4d205e74b214c95daf
23 lines
399 B
Forth
23 lines
399 B
Forth
Traditional Forth has a CREATE/DOES> construct. RETRO allows for
|
|
something similar using the `does` combinator.
|
|
|
|
An example in traditional Forth:
|
|
|
|
: acc ( n "name" -- )
|
|
create , does> dup >r @ dup 1+ r> ! ;
|
|
|
|
And in RETRO, using `does` and the `bi` combinator:
|
|
|
|
~~~
|
|
:acc (ns-)
|
|
d:create , [ [ fetch ] [ v:inc ] bi ] does ;
|
|
~~~
|
|
|
|
Here's a little test case:
|
|
|
|
~~~
|
|
#10 'foo acc
|
|
foo
|
|
foo
|
|
foo
|
|
~~~
|