Well, I can't say that I can do them any justice, but Dr. Ting describes them in his eForth literature.
I have some sample code, copied and roughly translated, but untested and not fully understood:
Code:
: COMPILE ( -- ) R> DUP @ , CELL+ >R ; COMPILE-ONLY
: [COMPILE] ( -- \ <string> ) ' , ; IMMEDIATE \ ??? What's that '\' doing in the stack comment ???
: <MARK ( -- a ) HERE ;
: >MARK ( -- A ) HERE 0 , ;
: <RESOLVE ( a -- ) , ;
: >RESOLVE ( A -- ) <MARK SWAP ! ;
: BEGIN ( -- a ) \ Start an infinite or indefinite loop structure
<MARK ; IMMEDIATE
: FOR ( -- a ) \ Start a FOR-NEXT loop structure
COMPILE >R <MARK ; IMMEDIATE
: AHEAD ( -- A ) \ Compile a forward branch instruction
COMPILE branch >MARK ; IMMEDIATE
: AFT ( a -- a A ) \ Jump to THEN in FOR-AFT-THEN-NEXT loop 1st time through
DROP [COMPILE] AHEAD [COMPILE] BEGIN SWAP ; IMMEDIATE
: THEN ( A -- ) \ Terminate a conditional branch structure
>RESOLVE ; IMMEDIATE
: NEXT ( a -- ) \ Terminate a FOR-NEXT loop structure
COMPILE next <RESOLVE ; IMMEDIATE
In the above, "next" is not the threaded interpreter, but a code word that decrements the index on the return stack and branches until it hits -1, then does an RDROP and proceeds. As I understand it, FOR NEXT is a simplified DO LOOP which counts down to zero by one, and AFT appears to be a clever internal modifier whose usefulness has so far eluded me. Here are a couple of examples of AFT being put to use ... maybe you can help me figure out what they're doing:
Code:
: _TYPE ( b u -- )
FOR AFT DUP C@ >CHAR EMIT 1 + THEN
NEXT DROP ;
: .S ( -- )
CR DEPTH
FOR AFT R@ PICK . THEN
NEXT ." <sp" ;
Mike B.