Re: acceptance of forth



Tinkerer Atlarge wrote: <1j9zm4j.qzwbt6zit6moN%tinkerer@xxxxxxxxxxxxxxx>
The secret might be to forget about constructs and consider the action
of WHILE and REPEAT as entities in their own right which only need
BEGIN as an end-marker for their own purposes. But that is just me
thinking aloud. I don't claim to know yet.

You could do that. It's probably better to start by just using the
basic three constructions, but I do somewhat think of them as individual
pieces.

My understanding goes something like this:

Forth has an unconditional branch and a branch-if-false. It also
differentiates between forward and backward branches. So we have six
basic words to compile these branches, and three convenience words which
combine the basic operations. These words use a stack at compile-time:


Forward Branches
----------------

IF/AHEAD ( -- branch )

Compile a forward (conditional?) branch, leaving a reference so we
can point it to the right place later.

THEN ( branch -- )

Resolve `branch` to jump here.

ELSE ( branch1 -- branch2 ) AHEAD SWAP THEN ; IMMEDIATE

-------------------->
Usually `IF <true-action> ELSE <false-action> THEN`.
---------------------->

It ends the <true-action> section with an unconditional `branch2`
which skips over the <false-action>, and then resolves the
branch-if-false from the IF (so that it jumps here to begin the
<false-action> section).


Backward Branches
-----------------

BEGIN ( -- addr )

Push a marker so that we can branch (loop) back to it.

UNTIL/AGAIN ( addr -- )

Loop (conditially?) back to the most recent BEGIN.

WHILE ( addr -- branch addr ) IF SWAP ; IMMEDIATE

--------------------->
Usually `BEGIN <test> WHILE <action> REPEAT`
<-----------------------

Branch forward out of a loop (putting the branch *under* the BEGIN
addr).

: REPEAT ( branch addr -- ) AGAIN THEN ; IMMEDIATE

loop back to the most recent BEGIN, then resolve the WHILE branch to
jump just outside the loop.


Then you can do crazy things like:

BEGIN <test1> WHILE <test2> WHILE
<action>
REPEAT <failed-test2> ELSE <failed-test1> THEN

:-)

--Josh
.



Relevant Pages

  • Re: fs hang in 2.6.27.y | Fwd: [Bug 15658] New: [PATCH] x86 constant_test_bit() prone to misoptimiza
    ... *addr' cast to 'unsigned long *' with subsequent unconditional jump to pause ... static inline void bit_spin_lock ... If the bit was already set, inner loop waits to reset it and so forth. ... or gets oversized) to commit the transaction into on-disk journal. ...
    (Linux-Kernel)
  • Re: moving pairs
    ... what won't loop on it's own unless the whole machine's set position is ... the moving pairs problem i can't find a webpage for. ... a whole machine that altogether has one position to be in, ... resolve another way. ...
    (comp.lang.c)
  • Re: Jump Take offs
    ... I am excited to hear about your progress on the loop. ... Ask your coach if you are making the mohawk curve too deeply before ... I do the flip from a 3-turn, and it's helped a lot to think of a fairly ... clobber the jump. ...
    (rec.sport.skating.ice.recreational)
  • Re: Loop non-jump
    ... Replying to my own post after last night's lesson in which coach didn't ... let me off the hook and we drilled the loop for a long time. ... to get the jump going. ... brain, and my arms, shoulders and head pay no attention either...so we ...
    (rec.sport.skating.ice.recreational)
  • Re: Loop non-jump
    ... backspin and the loop immediately seems much more doable (compared to ... When you jump on earth, you're not trying to get all the way ... I hate to admit it - sorry ant! ... the secure RBO, the solid alignment, the deep springing off the leg, ...
    (rec.sport.skating.ice.recreational)