[Ecls-list] Macros impossible in compiled function
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at gmail.com
Tue Dec 11 14:14:45 UTC 2012
On Tue, Dec 11, 2012 at 12:58 AM, Peter Enerccio <enerccio at gmail.com> wrote:
> Macrolet will make possible to do local macros, which are fine, but this
> is not what I meant.
> What I wanted is to define macros "safely", because the code is evaluated
> in different thread with safe symbols, thus it is first saved
> as lazy function.
>
You can define a global macro. You cannot apply it in the same form which
defines it because it is a local form. Note that this has nothing to do
with ECL, but with your understanding of Common Lisp.
(LAMBDA ()
;; Mistake 1. Assume that the forms below change the package
;; and that the IN-PACKAGE form will affect the DEFMACRO
(LET ((CORE::P *PACKAGE*) (CORE:THIS #<a GAME:CUBE>))
;; This IN-PACKAGE does nothing because none of what follows
;; uses the value of *package*
(IN-PACKAGE ANCA)
(HANDLER-CASE
(UNWIND-PROTECT
(PROGN
(PROGN
(DEFMACRO ANCA::RUNNABLE (&BODY ANCA::BODY)
(SI:QUASIQUOTE (LAMBDA () (SI:UNQUOTE-SPLICE ANCA::BODY))))
;; MISTAKE 2: Assume that RUNNABLE can be used right after DEFMACRO
;; This is not possible because this is in a LAMBDA
((ANCA::RUNNABLE (PRINT "Ahoj")))))
(SETF *PACKAGE* CORE::P))
(T (CORE::X)
(FUNCALL
#<bytecompiled-closure #<bytecompiled-function 00000000032387d0>>
#<a GAME:CUBE>
CORE::X)))
T))
If you want to define a macro, evaluate a form that defines it. This
changes the global status of your Lisp and the macro will be available to
further forms which are evaluated later.
(defun define-my-macro ()
(defmacro foo (a) `(print ,a)))
This is a perfectly fine code. If you run
(define-my-macro)
it will define the macro. And now you can type
(foo 2)
and this will be translated to (print 2). That's all.
But really, I do not understand what you want to achieve with the code
above and I think you need to learn more Common Lisp before just trying to
run any code.
Juanjo
--
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20121211/0c4ae269/attachment.html>
More information about the ecl-devel
mailing list