Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Jeff Fox <fox@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Mar 2009 09:28:40 -0700 (PDT)
On Mar 19, 8:24 am, Helmar <hel...@xxxxxxxxx> wrote:
Forth doesn't have macros. It
has much more.
I could ask now "what is a macro"? Forth does not know it that way,
but you could implement it if you want (that would be an EVALUATE
basically). Forth is flexible and that is it. Even the people that use
Forth are usually flexible (and that I like), even if some are very
much like a stone if they are proposed to move ;)
Grüße,
-Helmar
For almost thirty years Chuck Moore has used two wordlists to
simplify the compiler and language; forth and macro. Macros
execute at compile time like immediate words did thirty years
ago.
So now we also know what color a macro has: it has to be yellow.
<colorforth explanation>
No. In Chuck's colorforth green is more like "]" and yellow is
more like "["
They do something more like change the system's STATE to execute
or compile. However macros are searched first in compile mode
and macros actually execute at compile time.
Thus one can have a green or yellow DUP but IF is compile only
because it is a macro.
Both DUP and IF are defined in the color red which is like ":"
"IF" is a macro so it has to be green not yellow!
Chuck uses cyan to specify that macro is to be compiled and
executed later rather than green which says execute it now
in compile mode.
So macros are defined in red and used in green or cyan but
can never be yellow! That would fail.
The words "forth" and "macro" declare some time before red
defines a new word to say whether the word will have the
"macro" behavior similar to the concept of immediate words
in Forth from fourty years ago.
In addition to the traditional Forth concepts of compile-
time and run-time colorforth uses the idea of edit-time
execution words specified by the color blue. Wil Baden
used standard Forth macros invoked by the editor to
do something similar.
<\colorforth explanation>
And? As I said, you can ask now "what is a macro?". The very common
interpretation of this term is not that it is a part of the compiler
implementation.
In the colorforth case it is not part of the compiler kernel. After
boot the kernel compiles more forth code and macros to complete the
initial compiler.
In Forth it is sometimes hard to draw lines between OS, compiler, and
application. Much confusion arises from many terms having a different
meaning in Forth than in their most common use outside Forth.
In Forth the term macro is most often used to refer to a method to
copy source code into compiled code in a way that can be compiled at
a later time. It is one mechanism to allow the use of words that
have not yet been defined. You can't postpone, delay evaluation or
delay compilation, of a word in the dictionary if that word isn't
in the dictionary yet or is going to be redefined later without
using some mechanism like stub indirection, forward referencing,
etc. Each has different trade-offs.
If you use indirection than all previous uses of FOO may become
different when you redirect FOO. If you need to leave those
definitions to remain the same but want future use of FOO to
have new behavior then you can redefine it now and compile it
later to use words that don't exist yet using this macro
technique.
This technique also allows the system to apply any code optimization
that the compiler can do after it knows what other changes have been
made. If you need to specify a definition now that includes words
that aren't defined yet or are going to have their definitions
changed macros do what postpone can't.
So, as far ok, you've to note that immediate words are
still in common use. I guess this has something to do with the
standard ;)
Yes, and the first law of motion.
Things at rest tend to remain at rest, as you say, like stones. ;-)
Best Wishes
.
- Follow-Ups:
- References:
- Is Forth still interesting?
- From: Helmar
- Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: Richard Owlett
- Re: Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: John Passaniti
- Re: Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: rios . lucho
- Re: Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: John Passaniti
- Re: Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: Jecel
- Re: Of course it IS!!! - was once wimpily (Re: Is Forth still interesting?)
- From: John Passaniti
- Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Anton Ertl
- Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Helmar
- Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Jeff M.
- Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Helmar
- Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Jeff Fox
- Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- From: Helmar
- Is Forth still interesting?
- Prev by Date: Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- Next by Date: Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- Previous by thread: Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- Next by thread: Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
- Index(es):
Relevant Pages
|
Loading