2 ms·
That is not forth. Instead (leaving out a bit of compile-time/run-time distinction magic): - define [+] something like: : [+] 0 swap 0 do + loop ; - define (
by Someone 16y ago
That is not forth. Instead (leaving out a bit of compile-time/run-time distinction magic):
- define [+] something like:
: [+] 0 swap 0 do + loop ;
- define (+ as a word that pushes the address of [+] and the stack pointer onto the retun stack
- similarly define [-] and (- , [* ] and (* , and [/] and (/
- define ) as a word that takes the current stack pointer, pops that saved stack pointer from the return stack and subtracts it from it (this puts the number of arguments to [+] on the stack, pops the address of [+] from the return stack and calls it.
With that, "(* 4 (+ 5 6 ) )" becomes executable forth.