> If having it execute at run time requires the data stack and program
> stack to exist at run time, how would a mixed approach do anything,
> which integrates with the run-time side, at expand time?  Expand time
> doesn't have access to the stacks because they don't exist at that time.
> How would the two sides integrate?  I.e., how would they share their
> stacks, and how would they syntactically mix?  
>
> I can see that a very limited set of programs could be transformed at
> expand time, but it seems like those that could wouldn't happen because
> they're silly programs.  E.g., in my notation, the program
> (S 1 2 3 swap dup) could be transformed at expand time to (S 1 3 2 2).
> But why would anyone write a program like that?  If, at expand time, the
> relevant portion of the data stack is not known, which I think is nearly
> always the case, how could expand-time rewriting help?
>
> Sorry if I'm missing something.  I'd love to see how to do it.

You are right. You can use rewriting to either fully evaluate the
combination of the program stack and the data stack to a final result,
or just optimize the program stack to the extend possible without
knowing concrete values on the data stack. This optimization step
alone is valuable, since it resolves "towers of words" concatenative
programs are typically made of.

However, there is one obstacle in this optimization process, if you
look at rewriting the program stack only: quotations. If one really
wants to take benefit of an optimizing step, one should distinguish
quotations in their role of deferring the execution of code from
quotations which just package data as stacks or lists. You can
establish such a distinction notationally. Quotations deferring code
can be rewritten and optimized as well. Because quotations deferring
code are just program stacks whose data stack is not known, yet. The
process is recursive.

Dominikus

Reply via email to