[Openmcl-devel] with-package

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Sat Jan 12 07:32:59 PST 2013


yes it was a mistake I rewrote the macro as follows

(defmacro with-package ((&rest names) &body body)
  `(progn
     (use , at names)
     (let ((results (multiple-value-list (progn , at body))))
       (unuse ,@(reverse names))
       (values-list results))))


but your solution looks much better (deals with errors in body)

(defmacro with-package ((&rest names) &body body)
 `(progn
    (use , at names)
    (unwind-protect (progn , at body)
      (unuse ,@(reverse names)))))



Taoufik



On Sat, Jan 12, 2013 at 4:27 PM, Greg Pfeil <greg at clozure.com> wrote:

> On 12 Jan 2013, at 7:48, Taoufik Dachraoui <dachraoui.taoufik at gmail.com>
> wrote:
>
> > Now, I wanted to define with-package
> >
> > (defmacro with-package ((&rest names) &body body)
> >  `(progn
> >     (use , at names)
> >     , at body
> >     (unuse ,@(reverse names))))
> >
> >
> > But the problem when I use with-package as follows:
> >
> > ? *package*
> > #<Package "COMMON-LISP-USER">
> > ?  (with-package (calculus) (share 3))
> > NIL  ;;; I did not use CALCULUS::SHARE
> > ? (share 3)
> > 4
> > ?
>
> This is probably secondary to the problem you are running into, but
> shouldn't your macro look more like:
>
> (defmacro with-package ((&rest names) &body body)
>  `(progn
>     (use , at names)
>     (unwind-protect (progn , at body)
>       (unuse ,@(reverse names)))))
>
> So that 1) the result of the form is the result of BODY and 2) if BODY
> errors, your package still gets cleaned up.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20130112/4a95f71f/attachment.htm>


More information about the Openmcl-devel mailing list