retroforth/example/accumulator.forth
crc 320e100737 two new examples
FossilOrigin-Name: deab79dff5f0c935a74469f50ab8b04f557dcfe0da623d4d205e74b214c95daf
2017-10-20 03:32:34 +00:00

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
~~~