Sat Mar 22 19:20:59 EDT 2008

what is compilation of forth words?

essentially, in the current context, it's a source code map which
translates all forth words to macros that compile a call:

macro : abc 123 ;
forth : xyz abc abc ;


macro : abc 123 ;
      : xyz #x0010 execute ;

so what is the essence?  it's source transformation. i probably need
to perform some operation twice: one to construct some syntax, and
another one to evaluate functions. maybe first separate syntax and
semantics better?

let's try to catch the code first. it's probably easier to move from
using a 'continue' thunk to just recording the point of the next

catching code is problematic: there might be a macro that generates
several words or macros.. this cannot be cleanly cut out by cutting
out each definition. the only real thing is what comes out in the end:
that's what needs saving: the fully expanded nested let expression.

looking at this:

box-macro> (forth-words : abc 1 2 3 def : def 4 5 6 abc)
(forth-words-incremental (: abc 1 2 3 def : def 4 5 6 abc))
  (lambda (collect)
          (lambda (state)
            (macro/def ((literal 3) ((literal 2) ((literal 1) state)))))))
          (lambda (state)
            (macro/abc ((literal 6) ((literal 5) ((literal 4) state))))))))

actually gives the solution.
instead of expanding to something which includes dynamic binding, just
have them pass in as an argument. in this case: ditch the
'forth-definitions' and make 'mode-forth' and 'mode-macro' parameters.

this gives a very clean separation of function and structure: the
structure is just the expansion of all macros. function can be plugged
in later.

yep. works like a charm.

box-macro> (forth-rep (macro : abc 123 forth : def 345))
(lambda (forth macro collect)
    ((abc (macro 'abc (lambda (x) ((lit 123) x))))
     (def (forth 'def (lambda (x) ((lit 345) x)))))