DMD 1.005 release
Charles D Hixson
charleshixsn at earthlink.net
Wed Feb 7 17:10:07 PST 2007
janderson wrote:
> Andreas Kochenburger wrote:
>> BLS wrote:
>>> I guess here is a need for further explaination.
>>>
>>> Either I am an complete idiot (not completely unrealistic) and
>>> missunderstood something, or a new, quit radical, programming
>>> paradigmn change is on it s way. I mean it is difficult to realize
>>> the implications.
>>> Bjoern
>>
>> I am not a D programmer (yet) only observing what is happening.
>>
>> I compare the new "code generation at compile-time" stuff in D with
>> Forth. Forth also has a built-in interpreter & compiler which extends
>> the language and can also execute macros at compile-time through
>> EVALUATE. Of course Forth is much more low-level than D. But IMO the
>> new mixins are not a "radical programming paradigm change".
>>
>> Perhaps I just did misunderstand something?
>>
>> Andreas
>
> I'm not familiar with forth. Can you provide some examples? Does it
> allow partial macro definitions. Can you apply string operations on
> them at compile time?
>
> -Joel
Forth is a Polish, as opposed to reverse Polish, language.
Every word understood by the system is a command.
Forth doesn't exactly HAVE a grammar. What it has is two
stacks. (Sometimes more, but the additional stacks are
optional, and their usage is inconsistent at best.)
Forth commands generally operate on the stack. There are
exceptional commands, those marked IMMEDIATE, which operate on
the input stream.
E.g.:
1 means push a 1 to the top of the stack. (This is typical of
all integer literals. Floats are, or were, not standardized.)
+ means add together the top two items on the stack (removing
them from the stack) and push their sum onto the top of the stack.
dup means take the value (number?) at the to of the stack and,
without removing it, push it to the top of the stack.
does means examine the top of the stack. If it's true,
continue execution, if not, skip down to the word following
the end marker.
It's been too long or I'd give a few more examples. The
important thing to note is that words are executed without
respect to grammar, but with the ability to determine their
context.
Forth is very similar to LISP, only with a simpler grammar.
I.e., the grammar is simple serial execution, with certain
words (those marked immediate) able to manipulate the input
stream to determine what will be the next in order.
N.B.: I'm discussing a basic Forth system, approximating
FIG-FORTH, which is as close to standardized as Forth gets.
There have been considerable variations. My favorite was
Neon, an Object-Oriented Forth for the Mac from Kyria Systems
(now long defunct). If they hadn't died while attempting to
transition to MSWind95 I might have ended up as a Forth
programmer.
But don't confuse Forth, in any of it's variations, with D.
Forth didn't really create compiled code...and it also wasn't
an interpreter in any normal sense of the term. (I'd say
isn't, but I'm not really familiar with current Forths.)
Forth was what was called a "Threaded Interpretive Language".
It might be best to say that you didn't program Forth, you
built a software machine that when run did what you wanted to
program to accomplish.
OTOH, looked at from a different angle, the closest analog to
Forth is Smalltalk. But Smalltalk has too much grammar.
Still, they both have that system library that is grown by
users...and which makes the environment both richer and more
complicated to use than languages like D, where the libraries
are more distinct from the language.
More information about the Digitalmars-d-announce
mailing list