2 ms·
Here's my take on the Forth equivalent. Defining a DOUBLE word, the usual way, rather than anonymously. (Tricky to pick a good identifier that doesn't sound li
by MaxBarraclough 6y ago
Here's my take on the Forth equivalent.
Defining a DOUBLE word, the usual way, rather than anonymously. (Tricky to pick a good identifier that doesn't sound like it's doing something with double-precision floats.)
( num -- num_doubled )
: DOUBLE DUP + ;
Next up, we push 7 to the stack, define our 'function' (not a Forth term) anonymously using :NONAME which pushes an execution token value to the stack, then we immediately invoke it. This has the effect of printing 14.
7 :NONAME DUP + ; EXECUTE .
- MaxBarraclough 6y agoToo late to edit: the second example leaks memory, as the execution token is not destroyed before becoming inaccessible. As far as I know, ANS Forth doesn't offer a friendly interface for destroying execution tokens.