From: Henrik Motakef
Subject: Scope of (in-package)
Date: 
Message-ID: <87heg9u6gy.fsf@pokey.henrik-motakef.de>
Hi,

Could someone please explain (or tell me where to click in the
Hyperspec) the exact semantics of (in-package "foo"), especially the
"scope" of this declaration?

It looks like it binds *package* until the next (in-package ...)  or
the end of the currently loaded file occurs, and that the current
value of *package* gets passed to (load)ed files, but won't be
affected by (in-package) forms in those files. Is this correct? Where
can I find more information?

TIA
Henrik

From: Will Deakin
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <an58rh$6fs$1@venus.btinternet.com>
Henrik Motakef wrote:
> It looks like it binds *package* until the next (in-package ...)  or
> the end of the currently loaded file occurs, and that the current
> value of *package* gets passed to (load)ed files,
Yes. Why not try and put this into practise?

For example, in your editor of choice, create a file called 
fimble.lisp[1]. This should contain the following two lines:
(in-package :cl)
(format t "~A~%" *package*)

This simple file sets the package within the file to common-lisp -- not 
common-lisp-user -- and then outputs the name of the package to stdout.

At the command prompt of your lisp implementation della casa you could type:
* *package*
* (load "fimble.lisp")
* *package*

You should, I hope, find out what you wish to know.

> but won't be affected by (in-package) forms in those files.  Is this correct?
To me, this appears a little contorted. If you don't get what you expect 
from the above experiment, or even if you do, let us know how you get on.

> Where can I find more information?
There are lots of good books about. The Hyperspec is an excellent 
reference but is not intended as a tutorial. `Common Lisp the Language' 
by Steele, `ANSI Common Lisp' by Graham or PAIP by Norvig are all 
excellent sources of further information at this kind of level. I even 
believe CLTL2 is available on the web.

:)w
From: Will Deakin
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <an59ci$7aq$1@venus.btinternet.com>
I wrote:
> ...fimble.lisp[1]...
Damn my senility. The footnote is ment to read:

[1] The name is utterly arbitary but due in part to awareness of this 
programme due to an slightly niggly two year old who, in the absence of 
digital tv in my house and the fact that the fimbles are being 
constantly advertised on non-digital, is less than impressed. Should I 
add a note about the disapointment on such an individual also inherent 
in the stopping of the summer steam railway special or the conductor 
strikes disrupting train movements? You all know the answer and with 
that I bid you all a sweet goodnight.
From: Henrik Motakef
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <878z1lu4ih.fsf@pokey.henrik-motakef.de>
Will Deakin <···········@hotmail.com> writes:

>> It looks like it binds *package* until the next (in-package ...)  or
>> the end of the currently loaded file occurs, and that the current
>> value of *package* gets passed to (load)ed files,
> Yes. Why not try and put this into practise?

Of course, I did try it before asking. I just wanted to know if there
are any pitfalls I overlooked.

My main problem was that I couldn't find any reference to a "file" (or
some such, like a "compilation unit" in C) as a relevant concept with
regard to the package system anywhere in the Hyperspec, so I wondered
why EOF made *package* switch back. After looking again, I guess that
the line

| load binds *readtable* and *package* to the values they held before
| loading the file. 

in the entry for "load" clears things up a little - somehow it wasn't
clear to me that this behaviour was in the responsibility of "load".

Thanks,
Henrik
From: Will Deakin
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <an6uu4$2tv$1@paris.btinternet.com>
Henrik Motakef wrote:
> Of course, I did try it before asking. I just wanted to know if there
> are any pitfalls I overlooked.
Sure. Mea culpa as I didn't read this into what you posted.

> My main problem was that I couldn't find any reference to a "file" (or
> some such, like a "compilation unit" in C) as a relevant concept with
> regard to the package system anywhere in the Hyperspec
Sure. Please note: I am no lisp expert. However, I would humbly suggest 
that you take heed Erik Naggum's advice in his excellent posting in this 
thread. I initially found I was confused in the description and nature 
of variable scope and binding.

> After looking again, I guess that the line
> | load binds *readtable* and *package* to the values they held before
> | loading the file. 
> in the entry for "load" clears things up a little - somehow it wasn't
> clear to me that this behaviour was in the responsibility of "load".
Yes. I had a quick dig and found this pithy quote[1]:
`When a file has been loaded, the current package is always reset to the 
value it had before the load began.'

> Thanks,
`Non fa niente!' (Although I'm not sure I said anything useful other 
that a rather pointed a `RTFM (or another) again.'

:)w

[1] ANSI Common Lisp, Paul Graham p. 137, (1996) Prentice Hall
From: Erik Naggum
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <3242241619042048@naggum.no>
* Henrik Motakef
| Could someone please explain (or tell me where to click in the Hyperspec)
| the exact semantics of (in-package "foo"), especially the "scope" of this
| declaration?

  Have you looked at the entry for `*package*� and followed the links out of
  that page?

| It looks like it binds *package* until the next (in-package ...)  or the end
| of the currently loaded file occurs, and that the current value of *package*
| gets passed to (load)ed files, but won't be affected by (in-package) forms
| in those files.  Is this correct?  Where can I find more information?

  I think you are telling me that you do not quite understand the nature of
  special variables and dynamic bindings.  Therefore, you should read the
  first 5 chapters of the standard (HyperSpec) or the first several chapters
  of CLtL 2 which explains this very well.

-- 
Erik Naggum, Oslo, Norway                 Today, the sum total of the money I
                                          would retain from the offers in the
more than 7500 Nigerian 419 scam letters received in the past 33 months would
have exceeded USD 100,000,000,000.  You can stop sending me more offers, now.
From: Tim Bradshaw
Subject: Re: Scope of (in-package)
Date: 
Message-ID: <ey3k7l4zn2c.fsf@cley.com>
* Henrik Motakef wrote:

> It looks like it binds *package* until the next (in-package ...)  or
> the end of the currently loaded file occurs, and that the current
> value of *package* gets passed to (load)ed files, but won't be
> affected by (in-package) forms in those files. Is this correct? Where
> can I find more information?

IN-PACKAGE unilaterally assigns to *PACKAGE*.  However LOAD binds
*PACKAGE* to its current value before (or rather around) loading the
file, thus ensuring that IN-PACKAGE can not alter the binding of
*PACKAGE* current when LOAD is called.

--tim