[Openmcl-devel] eval-in-package

Taoufik Dachraoui taoufik.dachraoui at wanadoo.fr
Mon Jun 1 13:31:20 PDT 2009


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





More information about the Openmcl-devel mailing list