Josh Grams wrote:
> I've been thinking about Jonah Thomas's comment (back toward the
> beginning of this month) that there is a bunch of unnecessary
> complexity around IMMEDIATE/POSTPONE/etc and the divide between
> interpretation and compilation semantics.
>
> Coming mostly from languages other than Forth, it seems to me that
> the complexity comes from Forth offering the wrong choice to the
> programmer. I *think* that what I normally want as a programmer
> is a distinction between syntax and semantics (parse time and
> "run" time).
Different names, same concept. When we speak of "interpretation" we
mean "parse time".
> For instance, I want the behavior of S" to be: parse a string
> delimited by a double-quote, and add a string literal to the
> current "statement", regardless of whether or not I'm inside a
> definition.
That is precisely what S" as defined in the FILES wordset (as an
extension to the CORE S") does.
> : CHAR PARSE-WORD DROP C@[EMAIL PROTECTED]
LITERAL ; SYNTAX
> : S" CHAR " PARSE SLITERAL ; SYNTAX
Your word SYNTAX is, IMO, indistinguishable from IMMEDIATE. And this
definition of CHAR is what [CHAR] does. Your S" *doesn't* do what the
your description above does, in that it won't work if you're *not*
inside a definition. A "state-smart" word, that does different things
depending on whether you're compiling or interpreting, would look like
this:
: S" ( -- addr len ) PARSE STATE @[EMAIL PROTECTED]
IF SLITERAL THEN ; IMMEDIATE
> It would, of course, add a bit of complexity to the compiler. But
> I think it simplifies things for the programmer. And it has the
> advantage that each name only ever has one piece of code attached
> to it. And I believe you could have ANS compliance with basically
> just:
>
> TRUE CONSTANT STATE
> ' SYNTAX ALIAS IMMEDIATE
>
> I haven't implemented this, and of course I've skipped all the
> details here; I just wanted to present the basic idea. Thoughts?
I'm very unclear what you think SYNTAX does differently from IMMEDIATE.
In the late 70's a lot of people who were just starting with FORTH
really liked the idea of "STATE-smart" words, that did different things
depending on whether you were compiling or interpreting (either compiled
something or not). But after a few years' use, most of them came around
to the understanding that, except in a few specific circumstances,
STATE-smart words made things *harder* for the programmer, not easier.
So, whereas in the Forth79 meeting there was a lot of pressure for
STATE-smart words, by Forth83 and later that was mostly gone.
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."
==================================================


|