Thu Mar 20 08:40:18 EDT 2008


with scat ready, the next real problem is representation of forth
code. time for some "what is" exercises.

macros are not really the problem, but what is instantiated forth code?

(let-ns (macro)
    ((foo (macro: a bar))
     (bar (macro: c d e foo)))
  (let-ns (macro)
      ((baz  (forth: foo bar))
       (shma (forth: wikki wakki)))))

in the end, after compilation, this leads to:

(let-ns (macro)
    ((foo (macro: a bar))
     (bar (macro: c d e foo)))
  (let-ns (macro)
      ((baz  (macro: 123 compile))
       (shma (macro: 456 compile)))

so: a dictionary is a nested let-ns expression with a hole in
it. compilation is filling this hole to get a new nested let-ns

it looks like the key extension is to move the assembler to the syntax
level also.

so what does the 'forth:' form do?

  * it creates a macro which compiles a reference, and saves code for
    later compilation in that lexical environment (closure) bound to
    that reference.

so the essential part is to separate the creation of new names from
evaluation of the righthand sides + complete unification of forth
words and macros. (a forth word has a macro associated which compiles
its body).

testing this, but i'm missing an essential part of brood (compilation
stack pattern matching) to get this working. EDIT: worked around it
using base language.

what i got now:
(define empty-state
  (make-state '() '()))

(define (run-macro macro)
   (macro empty-state)))

(define-syntax forth:
  (syntax-rules ()
    ((_ . code)
     (let ((word
               (macro: . code)))))
       (base: ',word compile)))))

(define xxx
   ((abc   (macro: 1 2 3))
    (def   (macro: 4 5 6))
    (broem (forth: 123))
    (lala  (forth: abc def))
    (shama (forth: lala)))

   (macro: lala)))

looks like a pretty good implementation. it even has a means to only
compile what's necessary by adding an 'export' word: determine which
functions get exported into the namespace.

this structure creates a graph in which the nodes are forth words
(instantiated macros).