Comments in Forth code

The word ( - a left parenthesis followed by a space - says ``disregard all following text until the next right parenthesis or end-of-line in the input stream''. Thus we can add explanatory comments to colon definitions.


Stack comments are a particular form of parenthesized remark which describes the effect of a word on the stack. For example the comment ( x -- x x) could be used as the stack-effect comment for the word dup. The comment indicates that the word will make a copy of TOS and add it to the stack, leaving the original value, now as NOS.


The word \ (backslash followed by a space) is known as drop-line and is also available as a method of including longer comments. Upon executing, it drops everything from the input stream until the next carriage-return. Instructions to the user, clarifications of usage examples can be conveniently expressed in a block of text, with each line started by a backslash.




Peter Jacobs 2013-06-12