[Openmcl-devel] eval-in-package

Taoufik Dachraoui taoufik.dachraoui at wanadoo.fr
Sun May 31 03:15:08 PDT 2009


Dear,

I would like to write a function that evaluates a body in a given  
package

Example:

 >> ccl
 >(make-package 'test)
 >(in-package 'test)
 >(defun f(n) (if (< n 2) 1 (* n (f (1- n)))))
 >(in-package 'common-lis-user)
 >(format t "factorial of ~d is ~d~%" 5 (eval-in-package (find-package  
'test) (f 5)))
=> factorial of 5 is 120


I tried the follwoing but it does not work (eval uses null-lexical- 
bindings ?)

 >(defmacro eval-in-package (p f) `(let ((*package* ,p)) ,f))
 >(eval-in-package (find-package 'test) (f 5))

The purpose of the eval-in-package is to evaluate functions  
dynamically generated and must be evaluated in a given package.

Thank you in advance for your help

Kind regards
Taoufik Dachraoui




More information about the Openmcl-devel mailing list