Fri Apr 18 15:45:13 EDT 2008

for .. next

maybe i need to test this first: compile 2 branches + save the best in
memoized form such that nested loops are computed inside out in linear

           for         body         next
       dup for    drop body save    next drop

so, at the time 'for' executes, it needs to know which of the 2 is
shortest: (body) or (drop body save).

let's call the above: (for0 body next) and (for1 body next1) and
reserve (for) and (next) as the macros that setup the evaluation.

this leads to the following control logic:

  if 'for' can capture 'body', it can try several strategies and pick
  the best one.

can this be done using composable continuations? it would be the first
testing point to see if they mix well. if so, it can probably be
generalized to a lot more control structures.

i worry about nesting: for_o for_i .. next_i next_o would lead to
something like:

(lambda (state)
  (reset (next_o
          (reset (next_i
                   ;; for_i
                   (shift i
                          ;; for_o
                          (shift o

maybe they need different prompt tags? looks like it: the inner shift
won't see the outer reset. let's give it a try.

this needs to go deeper: since the rest of the code explicitly needs
to be called inside a dynamic extent.. confused now.



it's probably best to bring shift/reset to scat.

;; Installs a reset and saves the prompt tag on the stack.
(define-ns (macro) reset/tag
  (lambda (state)
    (let ((tag (make-continuation-prompt-tag 'reset)))
      (reset tag