[REBOL] Re: The effect of learning Forth on my understanding of REBOL
From: GedB:Rushcoding at: 23-Mar-2007 13:18
On 3/22/07, Gregg Irwin <gregg-pointillistic.com> wrote:
> If you could post some thoughts on this, it might help others. That
> is, how *do* you visualize that code working now.
The main breakthrough is 'what does a word do'.
My thinking was strictly imperetive, so every word is a procedure to
So if you have 'red', what does it do? Apparantly nothing.
So if you have 'a: if arg1 [red]' what happens when red is executed? Nothing?
My understanding before was that a block is an anonymous method with
an implicit return.
The actual code being executed was 'if arg1 do [return red]'.
Obviously If returns whatever is passed to it.
This was all very complicated, and never quite fitted. It was all
just too Ptolemaic.
To be honest, I would write if arg1 [a: red] just so I could keep a
track of it all in my head.
Now I see that what red does is place something on the stack, where it
remains until something picks it up. 'if' just leaves the stack
However, unlike FORTH, REBOL enforces a scricter scope. I imagine
that a: sets an expectation for a token, which needs to be satisfied
within a specific scope. The stack is cleared once the current scope
is left. This removes the need for reverse polish and constant drops.
This is why 'a: if false [red] if true [blue]' returns none rather then blue.
This leads us to the need for the 'all' and 'any' words, and what the
difference between them is. These are commands that control the
I'm sure my mental model will need further refinement, but it is a
serious breakthrough for me :)