Re: Dynamic unquote ( , )?



Kaz Kylheku wrote:
but the LIST is not evaluated, since this is a macro. So what ends up
happening is that this expands to the code:

(if *execute-mode*
(list 'do-stuff-with val)
(progn (collect-emit-buf) (push '(list 'do-stuff-with val)
*actions*))

In excute mode, the (LIST 'DO-STUFF-WITH VAL) doesn't do the right
thing now. Although it can correctly resolve the value of VAL from the
surrounding lexical environment, all it does is compute the expression
and throw it away.

In execute mode it creates a list, instead of evaluating the expression, yes.

In delayed mode, the expression (LIST 'DO-STUFF-WITH VAL) is evaled,
but it can't resolve the correct value of VAL.

No, in delayed mode it pushes a list of the symbol 'do-stuff-with, along with the *value* of val, at least until I modified the code :)

Later, the macro simply fetches all those Lisp expressions and lets the top-level-macro expand to all that code. Then the code can be compiled into a function.

You want this code to come out of the macro:

(if *execute-mode*
(do-stuff-with val)
(progn
(collect-emit-buf)
(push (lambda () (do-stuff-with val)) *actions*)))

From this pattern, it should be obvious how to write the macro which
build this out of (EMIT-ACTION (DO-STUFF-WITH-VAL)).

So *ACTIONS* isn't a list containing fragments of source code. It's a
list of first-class funtions (which are compiled if the places that
generate them are compiled!)

But then what would the macro expand to? Right now it outputs a list of all the collected statements to compile, and execute at runtime. But a macro can't return *functions*, can it?

You call these first class functions using FUNCALL, rather than EVAL.

Yes... still thinking...

The problem is to reconcile the old macro code with the new mode of simply running the code.

--
Suffering from Gates-induced brain leakage...
.



Relevant Pages

  • Re: What should (ignore-errors ((foo))) do?
    ... CLISP appears to expand before the form is executed. ... condition is not ignored and execution fails. ... Well, SBCL is a compiler-only implementation, so one argument COMPILE ... That doesn't really make sense to me since the macro _must_ have been ...
    (comp.lang.lisp)
  • Re: modifying array access syntax
    ... I published recent speculation on the ARRAY ... > are in fact remnants of the property lists of these Lisp-N ... these that were meaningful at compile time (FEXPR, FSUBR, and MACRO ...
    (comp.lang.lisp)
  • rpm and yum problems after fc2 to fc3 update
    ... I checked my rpm version ... error: Unterminated {: {lua: ... Macro %__policy_tree failed to expand ...
    (Fedora)
  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... It is not surprising -- in case of error, you leave resources unreleased. ... The only difference would be that the macro ... may expand to different code in release / debug versions. ... where allocation and deallocation occurs in one routine is not applicable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DISFAVORED Was: name for 3 PICK finally?
    ... complexity is reduced by reducing the phases of execution to keep ... outside happens when the word containing the macro executes. ... LITERAL COMPILE, .... ... ``GET LITERAL @ LITERAL `EXECUTE COMPILE,'' ...
    (comp.lang.forth)