[Openmcl-devel] eval-in-package
Taoufik Dachraoui
taoufik.dachraoui at wanadoo.fr
Mon Jun 1 13:53:00 PDT 2009
I would like to have more details, I do not understand why there is a
difference.
If you look at (eval (read-from-string str)) form, in both functions
read-from-string
is supposed to read from a string and I think that at that point in
both function the
string is the same "(setq a 1)"
so why ther eis a difference? thank you giving me more details.
I am planning to use this in production for lisp server allowing many
clients to connect to a lisp server and executes lisp commands.
I will try to modify the reader so that no one can access internal
symbols
from any other package. (I am not sure about how yet)
-Taoufik
On Jun 1, 2009, at 10:44 PM, Dan Weinreb wrote:
>
> 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