macro returning more than one form

Kenneth Tilton ken at tiltontec.com
Fri Mar 14 16:58:39 UTC 2014


On Fri, Mar 14, 2014 at 11:58 AM, Alessio Stalla <alessiostalla at gmail.com>wrote:

> At the top level, PROGN is treated as if each contained expression
> appeared at the top level. So generally wrapping a PROGN around the result
> is precisely what you need to do.
>
> However, since I see an IN-PACKAGE form in your example... beware that
> that IN-PACKAGE form will NOT affect the following DEFUN, because the
> symbols in it will have been read long before the IN-PACKAGE is executed.
>

Yikes, I read too fast, did not see the in-package. Well, the "doing
something else wrong" suggestion stands. :) But this works in Allegro CL:

(defmacro go4it (n)
  `(progn
     (in-package :mcna.db)
     (defun forty2 () ,n)))

(go4it 42)

(print (forty2))

I put this in a source file in a library source with a different package,
in a Lisp session where :mcna.db was already a Lisp package.

I do find supplying an in-package form in a macro expansion alarming,
though. I never use it, but would use-package work?

-hp



>
>
>
> On Fri, Mar 14, 2014 at 4:45 PM, Paul Tarvydas <paultarvydas at gmail.com>wrote:
>
>> What is the best way to write a macro that returns more than one form to
>> the top level?  E.g.
>>
>> (in-package :xxx)
>> (defun ...)
>>
>> I've been wrapping a progn around the result, but LW doesn't like it very
>> much, and SBCL seems to hate it.
>>
>> Thanks
>> pt
>>
>>
>>
>


-- 
Kenneth Tilton
Fort Lauderdale, FL
http://tiltontec.com
http://socialalgebra.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20140314/9751d3a9/attachment.html>


More information about the pro mailing list