Re[2]: [colorforth] DOES> How is colorForth different from other Forths?
- Subject: Re[2]: [colorforth] DOES> How is colorForth different from other Forths?
- From: Mark Slicker <maslicke@xxxxxxxxxxx>
- Date: Mon, 15 Dec 2003 19:54:07 -0500 (EST)
On Mon, 15 Dec 2003, Jeff wrote:
> The structure problem that we've been tossing back and forth is a
> perfect example of what I'm thinking:
>
> Large programs are not written in assembly, because the design and
> implementation must be perfect the first time (and excellently
> documented). Forth is beautiful because it is only slightly higher
> level than assembly and practically documents itself.
You know, Forth can also be an assembly language; the machine language of
a microprocessor.
I think large programs are not written in register based assembly because
it is a statement based language, and there is no really good way to
pass parameters to and from procedures. The more powerful languages are
all based on expressions. Besides this register based languages all
vary in the kinds of addressing modes supported, so code is not very
portable.
The problem with register based assembly language is not that it is a
machine language, but that is non-portable and has a very poor level of
expression.
> In many of Chuck and Mr. Fox's writings and speeches that I have read,
> I have been humbled by their experience and wisdom I gain. But in the
> back of my mind I'm thinking, "this is great! assuming it is done
> right the first time..." The structures problem above is trivial.
> Simple. But it is still a real-world problem. And I keep coming back
> to it not because the answer wasn't given, but that the answer (each
> time) has been to hard-code it (check that, Mark's sample was very
> nice, indeed).
I'll put it in more detail now, so you at least know what is involved:
forth
: here4 here 3 ? if 1, here4 ; then 2/ 2/ ;
: defer pop ;
: allot defer here4 swap for 0 , next ; macro
: literal [?dup] b8 1, , ;
: struct 0 ;
: field dup [literal + ;] 1 + ;
: end-struct [literal] allot [literal push ;] ; forth
: point struct
: x field
: y field
: point end-struct
What I have done here is simply used the provided facilities of
colorForth. One thing comes to my attention is that if the semantics of
[cyan] were changed slighty so that [allot] would compile a code to
compile a call to allot the expression of this particular code becomes
simpler and more intuitive.
forth
: here4 here 3 ? if 1, here4 ; then 2/ 2/ ;
: allot here4 swap for 0 , next ; macro
: literal [?dup] b8 1, , ;
: struct 0 ;
: field dup [literal + ;] 1 + ;
: end-struct [literal allot ;] ; forth
: point struct
: x field
: y field
: point end-struct
The technique in both cases is to use macros to compile whole procedures
inline.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com