forth and RPN/RPL
As Doug says, there's no distinction in Forth between user-defined words and
"language" words. Conventionally, words expect numeric arguments on the
data stack, which implies a post-fix order, but text strings are parsed by
reading forward in the input stream. This means that all defining words (of
which : and VARIABLE are examples) are followed by the name of the word
being defined. Consider the defining word CONSTANT:
1000 CONSTANT BIG
The word CONSTANT expects a numeric argument on the stack, 1000 in this
case, and defines a word, named BIG in this case. When BIG is executed, it
will return the value 1000.
Users can add defining words, and they will follow a similar convention.
Well, I don't know anything about Lisp or Scheme, but one can make macros in
Forth. For example:
: DOUBLE ( -- ) POSTPONE DUP POSTPONE + ; IMMEDIATE
When DOUBLE is encountered (presumably inside a colon definition), it will
comjpile references to DUP and + . There's no particular advantage in doing
this, though, and it isn't done often. The major use of it is to make
custom flow-of-control words, and that's a need that crops up fairly rarely.
But you could, if you wished, define:
: -IF ( -- src ) POSTPONE 0= POSTPONE IF ; IMMEDIATE
Cheers,
Elizabeth
--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454
Hawthorne, CA 90250
http://www.forth.com
"Forth-based products and Services for real-time
applications since 1973."
==================================================
|