[Openmcl-devel] eval-in-package

Dan Weinreb dlw at itasoftware.com
Mon Jun 1 13:44:06 PDT 2009


The difference is that the first one is printing
in the context of "pkg" but the second is
printing in the context of the current package.

This is probably all educational for you, but
you should know that no real Lisp program
would do anything like this.



Taoufik Dachraoui wrote:
> Hi
>
> I wrote 2 functions slightly different to evaluate a lisp body in a  
> given package
> one is wrong and the other is correct at least for the test I run).
>
> The problem I could not understand why this is so, both functions  
> looks correct
> as far as I can tell;
>
> (make-package 'here)
> (make-package 'there)
>
> (in-package 'here)
>
> (defun eval-in-package-1 (pkg) ; wrong
>    (let ((req (read))
> 	(*package* (find-package pkg)))
>      (eval (read-from-string (format nil "~S" req)))))
>
> (defun eval-in-package-2 (pkg)  ; correct
>    (let ((req (format nil "~S" (read)))
> 	(*package* (find-package pkg)))
>      (eval (read-from-string req))))
>
>
> ? (eval-in-package-1 'there)
> (setq a 1)
>
> 1
> ?
> ? (eval-in-package-2 'there)
> (setq b 1)
>
> 1
> ?
> ? here::a								;;;;;;;;;; wrong; a must be defined in package there
> 1
> ? here::b								;;;;; this correct, b is defined in package there
>  > Error: Unbound variable: B
>  > While executing: CCL::TOPLEVEL-EVAL, in process listener(1).
>  > Type :GO to continue, :POP to abort, :R for a list of available  
> restarts.
>  > If continued: Retry getting the value of B.
>  > Type :? for other options.
> 1 > :pop
>
> ? there::a									
>  > Error: Unbound variable: THERE::A
>  > While executing: CCL::TOPLEVEL-EVAL, in process listener(1).
>  > Type :GO to continue, :POP to abort, :R for a list of available  
> restarts.
>  > If continued: Retry getting the value of THERE::A.
>  > Type :? for other options.
> 1 > :pop
>
> ? there::b				;; correct
> 1
> ?
>
>
>
> Kind regards
>
> -Taoufik
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>   



More information about the Openmcl-devel mailing list