4 ms·
Stack-based programming does not need extra syntax characters (what you call quotes and brackets) to structure the program. arithmetic syntax: (a+b)*c lis
by dvdkhlng 13y ago
Stack-based programming does not need extra syntax characters (what you call quotes and brackets) to structure the program.
arithmetic syntax: (a+b)*c
lisp syntax (polish notation): (* (+ a b) c)
forth syntax (reverse polish notation): a b + c *
In fact all words in Forth are only separated by whitespace. However, to "emulate" more complex syntax, some words in Forth are marked to be executed immediately upon parsing (somewhat like "macros" in lisp) and then access the input stream to extract more than whitespace-separated tokens. Exampes:
'(' parses comments : ( comment)
's"' compiles string literals : s" abc"
'[if]' conditionally skips code fragments: 0 [IF] bla [THEN]
Still the macro word itelsf needs to be whitespace-delimited.
- zaf 13y agoAh, so you mean that certain words can not only look at the stack but also look at manipulate the input word stream. Thanks for the explanation. I really ought to do a practical session with Forth.
- dvdkhlng 13y agoThere are various levels of abstraction when accessing the input stream. The lowest level is by inspecting the input (line) buffer. Just realized how that allows one to write a three-word quine [1] in ANS-compliant Forth: SOURCE TYPE BYE [1] https://en.wikipedia.org/wiki/Quine_%28computing%29 https://en.wikipedia.org/wiki/Quine_%28computing%29