[Ecls-list] Macros impossible in compiled function

Peter Enerccio enerccio at gmail.com
Tue Dec 11 15:19:51 UTC 2012


Ah, thank you. I guess that was the problem, I didn't think about the local
definition, since technically, you can define function and use it right
away in the same local code. I will have to think how to remedy it, I
suppose.

The reason why there is in-package is strange, because I don't know what
does in-package do in ecl, but if the in-package is not there, the results
are undefined (for instance when there is unbound symbol, it will not
report the error as condition, for instance) thus I left it there, even
though it has zero technical meaning, because there is no reading involved
at that point.

As for the reason why, it's because the whole code there is compiled into
function which is then called at later time in different thread.
Results are like this then:
http://img15.hostingpics.net/pics/864433capture1355165935.png


2012/12/11 Juan Jose Garcia-Ripoll <juanjose.garciaripoll at gmail.com>

> 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
>



-- 
Bc. Peter Vaňušanik
http://www.bishojo.tk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20121211/eaa21602/attachment.html>


More information about the ecl-devel mailing list