From: Zellyn Hunter
Subject: Ugly package problems
Date: 
Message-ID: <63rp2i$i5t@solaria.cc.gatech.edu>
Okay, here's an ugly one for you gurus out there.

I have a stream with lisp-expressions coming in, just like a lisp
file containing functions, which I want to evaluate...  I figure just
a repeated (eval (read stream)) until the stream empties out, right?
I know one of the functions will be called, let's say, "go".

Okay, but here's the trick.  I want everything to be defined in a new
package, so there can be little chance of conflict.  I want to call
that "go" function.

The problem I'm having is that even if I (make-package gensym) and set
*package* to the value it returns, things still don't get defined in
the package.

-----------------------------------------
Here's a sample of the basic problem:  Since I wasn't sure if some
assignments are done at parse-time, I put in a read-from string
thing, but even that doesn't work...  yeccchhhh.

We create k:bbb, but it still accesses var in the user package...


[1] USER(2): (make-package 'k)
#<The K package>
[1] USER(3): (defun k::bbb () (setq var 3))
K::BBB
[1] USER(4): (progn (setq *package* (find-package 'k))
                    (eval (read (make-string-input-stream "(bbb)")))
                    (setq *package* (find-package 'user)))
#<The COMMON-LISP-USER package>
[1] USER(5): var
3
[1] USER(6): k::var
Error: Attempt to take the value of the unbound variable `K::VAR'.
  [condition type: UNBOUND-VARIABLE]
-------------------------------------------


--
Zellyn Hunter                       Loneliness is a
······@cc.gatech.edu               terrible price to
404-206-1729                      pay for independence

From: William Paul Vrotney
Subject: Re: Ugly package problems
Date: 
Message-ID: <vrotneyEJ83A7.JyH@netcom.com>
In article <··········@solaria.cc.gatech.edu> ······@cc.gatech.edu (Zellyn
Hunter) writes:

> 
> Okay, here's an ugly one for you gurus out there.
> 
> I have a stream with lisp-expressions coming in, just like a lisp
> file containing functions, which I want to evaluate...  I figure just
> a repeated (eval (read stream)) until the stream empties out, right?
> I know one of the functions will be called, let's say, "go".
> 
> Okay, but here's the trick.  I want everything to be defined in a new
> package, so there can be little chance of conflict.  I want to call
> that "go" function.
> 

It's not ugly, your example is just problematical.

When you say you want everything to be defined in a new package your PROGN
is fine in that every unqualified symbol in the stream will be defined in
that new package.  But in your given example (way below) you do not read in
the k::bbb defun and therefore VAR will not occur in this stream and not get
defined in the k package.  So a solution to your problem as you have
depicted in the example is impossible in that you told k::bbb to *always*
set USER::VAR to 3.  For example this will work

    (in-package :k)

    (defun k::bbb () (setq var 3))

    (let ((*package* (find-package :k)))
      (eval (read (make-string-input-stream "(bbb)"))))

And this will work

  (let ((*package* (find-package :k)))
    (eval (read (make-string-input-stream
                 "(progn (defun k::bbb () (setq var1 3)) (bbb))"))))



But it is not clear from your example that either of these helps with your
actual problem.



Note: I've used LET *package* instead of your SETQ *package* which amounts
to roughly the same thing, but if you want to temporarily bind *package* it
is better to do it with a LET; when exiting the LET it will automatically
get rebound to the package it was before entering.



> The problem I'm having is that even if I (make-package gensym) and set
> *package* to the value it returns, things still don't get defined in
> the package.
> 
> -----------------------------------------
> Here's a sample of the basic problem:  Since I wasn't sure if some
> assignments are done at parse-time, I put in a read-from string
> thing, but even that doesn't work...  yeccchhhh.
> 
> We create k:bbb, but it still accesses var in the user package...
> 
> 
> [1] USER(2): (make-package 'k)
> #<The K package>
> [1] USER(3): (defun k::bbb () (setq var 3))
> K::BBB
> [1] USER(4): (progn (setq *package* (find-package 'k))
>                     (eval (read (make-string-input-stream "(bbb)")))
>                     (setq *package* (find-package 'user)))
> #<The COMMON-LISP-USER package>
> [1] USER(5): var
> 3
> [1] USER(6): k::var
> Error: Attempt to take the value of the unbound variable `K::VAR'.
>   [condition type: UNBOUND-VARIABLE]
> -------------------------------------------
> 
> 
> --
> Zellyn Hunter                       Loneliness is a
> ······@cc.gatech.edu               terrible price to
> 404-206-1729                      pay for independence
-- 

William P. Vrotney - ·······@netcom.com
From: Rainer Joswig
Subject: Re: Ugly package problems
Date: 
Message-ID: <34617EB4.A2E916A7@lavielle.com>
Zellyn Hunter wrote:

> [1] USER(2): (make-package 'k)
> #<The K package>
> [1] USER(3): (defun k::bbb () (setq var 3))

Here you are using USER::VAR. Not K::VAR. Hence the error.

> K::BBB
> [1] USER(4): (progn (setq *package* (find-package 'k))
>                     (eval (read (make-string-input-stream "(bbb)")))
>                     (setq *package* (find-package 'user)))
> #<The COMMON-LISP-USER package>
> [1] USER(5): var
> 3
> [1] USER(6): k::var
> Error: Attempt to take the value of the unbound variable `K::VAR'.
>   [condition type: UNBOUND-VARIABLE]
> -------------------------------------------

(defpackage "FOO")

(defun test ()
  (let ((expressions "(defun fak (n) (if (zerop n) n (+ n (fak (1-
n)))))
(print (fak 10))"))
    (with-input-from-string (stream expressions)
      (let ((*package* (find-package "FOO")))
        (loop for expression = (read stream nil nil)
              while expression
              do (eval expression))))))