[Openmcl-devel] with-package

Greg Pfeil greg at clozure.com
Sat Jan 12 07:27:49 PST 2013


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.


More information about the Openmcl-devel mailing list