From: Johan Ur Riise
Subject: ilisp and (in-package ...)
Date: 
Message-ID: <87g07gu8re.fsf@dill.topp.dyndns.com>
This puzzles me.
When type (in-package :unix) in the inferior lisp buffer
(buffer *cmulisp* in my case), and then evaluate *package*
in the sam buffer, it says package unix as expected.

But when I try to do the same in a normal ilisp buffer
(M-x lisp-mode), sometimes the in-package form works, sometimes
not. I use C-c n to evaluate the two forms in an ilisp-buffer.

Is this normal?
J.

From: Thomas F. Burdick
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <xcvvggciz01.fsf@famine.OCF.Berkeley.EDU>
Johan Ur Riise <·@rsc.no> writes:

> This puzzles me.
> When type (in-package :unix) in the inferior lisp buffer
> (buffer *cmulisp* in my case), and then evaluate *package*
> in the sam buffer, it says package unix as expected.
> 
> But when I try to do the same in a normal ilisp buffer
> (M-x lisp-mode), sometimes the in-package form works, sometimes
> not. I use C-c n to evaluate the two forms in an ilisp-buffer.
> 
> Is this normal?

Yep.  Say you have a file:

  (defpackage :foo)
  (in-package :foo)

  *package*  ; #1

  (in-package :common-lisp-user)

  *package*  ; #2

If you evaluate *package* #1, you'll get the FOO package.  If you
evaluate #2, you'll get the COMMON-LISP-USER package.  ILISP is smart
enough to find the in-package forms.  This is almost always a good
thing.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Johan Ur Riise
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <87d72ktvtw.fsf@dill.topp.dyndns.com>
···@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Johan Ur Riise <·@rsc.no> writes:
> 
> > This puzzles me.
> > When type (in-package :unix) in the inferior lisp buffer
> > (buffer *cmulisp* in my case), and then evaluate *package*
> > in the sam buffer, it says package unix as expected.
> > 
> > But when I try to do the same in a normal ilisp buffer
> > (M-x lisp-mode), sometimes the in-package form works, sometimes
> > not. I use C-c n to evaluate the two forms in an ilisp-buffer.
> > 
> > Is this normal?
> 
> Yep.  Say you have a file:
> 
>   (defpackage :foo)
>   (in-package :foo)
> 
>   *package*  ; #1
> 
>   (in-package :common-lisp-user)
> 
>   *package*  ; #2
This is great. Thamk you guys. Didn't know ilisp would take into
account other forms than those ecaluated.
From: Alain Picard
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <86vggc31lx.fsf@gondolin.local.net>
···@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

>  Say you have a file:
> 
>   (defpackage :foo)
>   (in-package :foo)
> 
>   *package*  ; #1
> 
>   (in-package :common-lisp-user)
> 
>   *package*  ; #2
> 
> If you evaluate *package* #1, you'll get the FOO package.  If you
> evaluate #2, you'll get the COMMON-LISP-USER package.  ILISP is smart
> enough to find the in-package forms.  This is almost always a good
> thing.
> 

That's a nice theory.  However, on ILISP with
ilisp-*version* = "5.11", it doesn't work; it
give me the #<PACKAGE COMMON-LISP-USER> package for both forms.

Any hints as to what I'm doing wrong?  

-- 
It would be difficult to construe        Larry Wall, in  article
this as a feature.			 <·····················@netlabs.com>
From: Thomas F. Burdick
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <xcvg07gtq5d.fsf@conquest.OCF.Berkeley.EDU>
Alain Picard <·······@optushome.com.au> writes:

> ···@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> 
> >  Say you have a file:
> > 
> >   (defpackage :foo)
> >   (in-package :foo)
> > 
> >   *package*  ; #1
> > 
> >   (in-package :common-lisp-user)
> > 
> >   *package*  ; #2
> > 
> > If you evaluate *package* #1, you'll get the FOO package.  If you
> > evaluate #2, you'll get the COMMON-LISP-USER package.  ILISP is smart
> > enough to find the in-package forms.  This is almost always a good
> > thing.
> 
> That's a nice theory.  However, on ILISP with
> ilisp-*version* = "5.11", it doesn't work; it
> give me the #<PACKAGE COMMON-LISP-USER> package for both forms.
> 
> Any hints as to what I'm doing wrong?  

That's the same version I'm using, so my only guess is that it's
something in your site-init, .emacs, or .ilisp file.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Johan Ur Riise
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <87adxotjbt.fsf@dill.topp.dyndns.com>
···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Alain Picard <·······@optushome.com.au> writes:
> 
> > ···@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> > 
> > >  Say you have a file:
> > > 
> > >   (defpackage :foo)
> > >   (in-package :foo)
> > > 
> > >   *package*  ; #1
> > > 
> > >   (in-package :common-lisp-user)
> > > 
> > >   *package*  ; #2
> > > 
> > > If you evaluate *package* #1, you'll get the FOO package.  If you
> > > evaluate #2, you'll get the COMMON-LISP-USER package.  ILISP is smart
> > > enough to find the in-package forms.  This is almost always a good
> > > thing.
> > 
> > That's a nice theory.  However, on ILISP with
> > ilisp-*version* = "5.11", it doesn't work; it
> > give me the #<PACKAGE COMMON-LISP-USER> package for both forms.
> > 
> > Any hints as to what I'm doing wrong?  
> 
> That's the same version I'm using, so my only guess is that it's
> something in your site-init, .emacs, or .ilisp file.

Ahh.. looks like the command C-c p in a lisp-mode buffer under ilisp
works like this:

if a defpackage is encountered before a in-package form in a buffer,
the last in-package form in the buffer is used.

if an in-package form is encountered first, that form (the first
in-package form) is used.

agree? 
From: Will Deakin
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <3BF3B112.6050006@hotmail.com>
Johan Ur Riise wrote:

> if a defpackage is encountered before a in-package form in a buffer,
> the last in-package form in the buffer is used.
> 
> if an in-package form is encountered first, that form (the first
> in-package form) is used.
> 
> agree? 

Yes. Without code grovelling, it certainly looks that way.

:)w
From: Marco Antoniotti
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <y6c7kssgjdb.fsf@octagon.mrl.nyu.edu>
Will Deakin <···········@hotmail.com> writes:

> Johan Ur Riise wrote:
> 
> > if a defpackage is encountered before a in-package form in a buffer,
> > the last in-package form in the buffer is used.
> > 
> > if an in-package form is encountered first, that form (the first
> > in-package form) is used.
> > 
> > agree? 
> 
> Yes. Without code grovelling, it certainly looks that way.

Yep.  I remember discussing this quite a long time ago (if I remember
correctly - without checking the logs - this went in just pre 5.10.*)
over the mailing list.  Most of the work was done by Marty Aztmueller
(and many others as well).  This was a consensus decision, and it
looked like the best solution.

Note that it works very well if you follow the rule "one DEFPACKAGE in
one separate file" and "one IN-PACKAGE per file".

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Raymond Toy
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <4nk7wsc6wf.fsf@rtp.ericsson.se>
>>>>> "Marco" == Marco Antoniotti <·······@cs.nyu.edu> writes:


    Marco> Yep.  I remember discussing this quite a long time ago (if I remember
    Marco> correctly - without checking the logs - this went in just pre 5.10.*)
    Marco> over the mailing list.  Most of the work was done by Marty Aztmueller
    Marco> (and many others as well).  This was a consensus decision, and it
    Marco> looked like the best solution.

    Marco> Note that it works very well if you follow the rule "one DEFPACKAGE in
    Marco> one separate file" and "one IN-PACKAGE per file".

Except when you have that one in-package conditionalized on the
platform, like, for, example MK defsystem.  Then it almost always gets
the wrong in-package.

I think.  I hacked up my copy of ilisp to make it look at the -*- mode
line and pull out the package there if possible before looking for
in-package stuff, so I don't notice these kinds of problems anymore.

Ray
From: Marco Antoniotti
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <y6cadxngay6.fsf@octagon.mrl.nyu.edu>
Raymond Toy <···@rtp.ericsson.se> writes:

> >>>>> "Marco" == Marco Antoniotti <·······@cs.nyu.edu> writes:
> 
> 
>     Marco> Yep.  I remember discussing this quite a long time ago (if I remember
>     Marco> correctly - without checking the logs - this went in just pre 5.10.*)
>     Marco> over the mailing list.  Most of the work was done by Marty Aztmueller
>     Marco> (and many others as well).  This was a consensus decision, and it
>     Marco> looked like the best solution.
> 
>     Marco> Note that it works very well if you follow the rule "one DEFPACKAGE in
>     Marco> one separate file" and "one IN-PACKAGE per file".
> 
> Except when you have that one in-package conditionalized on the
> platform, like, for, example MK defsystem.  Then it almost always gets
> the wrong in-package.

`defsystem.lisp' is admittedly a mess.  I definitively do not expect
much of ILISP when dealing with it :)

> I think.  I hacked up my copy of ilisp to make it look at the -*- mode
> line and pull out the package there if possible before looking for
> in-package stuff, so I don't notice these kinds of problems anymore.

That is a good thing. Why don't you submit it to the ILISP lists?  It
can make it in the CVS really fast.

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Raymond Toy
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <4ng07fd9ry.fsf@rtp.ericsson.se>
>>>>> "Marco" == Marco Antoniotti <·······@cs.nyu.edu> writes:

    Marco> Raymond Toy <···@rtp.ericsson.se> writes:

    >> I think.  I hacked up my copy of ilisp to make it look at the -*- mode
    >> line and pull out the package there if possible before looking for
    >> in-package stuff, so I don't notice these kinds of problems anymore.

    Marco> That is a good thing. Why don't you submit it to the ILISP lists?  It
    Marco> can make it in the CVS really fast.

Mostly laziness, but if it goes into CVS really fast, that would be
cool.

Looking up the ILISP lists and my hacked version....

Ray
From: Raymond Toy
Subject: ilisp and package from attribute line [Re: ilisp and (in-package ...)]
Date: 
Message-ID: <4nlmh28yvn.fsf_-_@rtp.ericsson.se>
>>>>> "Marco" == Marco Antoniotti <·······@cs.nyu.edu> writes:

    Marco> That is a good thing. Why don't you submit it to the ILISP lists?  It
    Marco> can make it in the CVS really fast.

I've submitted via the patch thingie.  It's short, so here it is
again for anyone who wants to use it.

It's one new function and a defadvice because I got tired of patching
the ilisp sources everytime I updated ilisp.

Ray


(defun parse-attribute-list (&optional buffer)
  "Find the attribute list in the given buffer (or current buffer, if
none) and return an alist of attribute/value pairs.  The attributes
are (lowercase) symbols, and the values are symbols or lists."
  (let ((buf (or buffer (current-buffer)))
	attrib-alist end)
    (save-excursion
      (set-buffer buf)
      (goto-char (point-min))
      (end-of-line)
      (setq end (point))
      (goto-char (point-min))
      (when (search-forward "-*-" end t)
	(while (re-search-forward "\\s-*\\(\\sw+\\):\\s-*" end t)
	  ;; Got a key word.  Get it and then read the value.
	  (push (cons (intern (downcase
			       (buffer-substring (match-beginning 1)
						 (match-end 1))))
		      (list (read (current-buffer))))
		attrib-alist)))
      (nreverse attrib-alist))))
(defadvice lisp-buffer-package-internal (around get-package-from-attribute activate)
  "Try to find the package from the attribute line of the file.  If
  not, use the standard technique to find the package."
  (let* ((file-parsed-attributes (parse-attribute-list))
	 (pkg (and file-parsed-attributes (second (assoc 'package file-parsed-attributes)))))
    ;; If we found the package in the file attributes massage it into
    ;; a valid package name.  If not, look for in-package or
    ;; def-package forms
    (if pkg
	(setq ad-return-value
	      (values (upcase (cond ((keywordp pkg)
				     (substring (symbol-name pkg) 1))
				    ((symbolp pkg)
				     (symbol-name pkg))
				    ((listp pkg)
				     (let ((p (first pkg)))
				       (if (symbolp p)
					   (symbol-name p)
					 p)))))
		      nil))
      ad-do-it)
    ad-return-value))
From: Will Deakin
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <3BF3E41C.2060306@hotmail.com>
Marco wrote:

> Note that it works very well if you follow the rule "one DEFPACKAGE in
> one separate file" and "one IN-PACKAGE per file".

Ooops. Thanks. I should have said this since I'd not come accross 
this problem because of following this sagely advice...

:)w
From: Alain Picard
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <86r8qz2dwk.fsf@gondolin.local.net>
Will Deakin <···········@hotmail.com> writes:

> Johan Ur Riise wrote:
> 
> > if a defpackage is encountered before a in-package form in a buffer,
> > the last in-package form in the buffer is used.
> > if an in-package form is encountered first, that form (the first
> > in-package form) is used.
> > agree?
> 
> Yes. Without code grovelling, it certainly looks that way.
> 

Hum.  For the life of me, I can't see why that's a good solution.
How would always looking for the first (in-package) form above the
form being evaluated ever get it wrong?

Also, Raymond, if that hack to look at the -*- package -*- emacs
line ever gets into ilisp, I'd be eternally grateful... :-)



-- 
It would be difficult to construe        Larry Wall, in  article
this as a feature.			 <·····················@netlabs.com>
From: Will Deakin
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <3BF391B2.6080102@hotmail.com>
Alain wrote:

> Any hints as to what I'm doing wrong?  

Don't know.

(defpackage :foo)
(in-package :foo)

*package* ;in foo

(defpackage :bar)
(in-package :bar)
*package* ;in bar

(in-package :cl-user)
*package* ;in common-lisp-user

If you are talking about the buffer package, that is a different 
thing. This is based on the last (in-package ...) declaration in the 
buffer.

:)w
From: Alain Picard
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <86n11n2dns.fsf@gondolin.local.net>
Will Deakin <···········@hotmail.com> writes:

> 
> (defpackage :foo)
> (in-package :foo)
> 
> *package* ;in foo
> 
> (defpackage :bar)
> (in-package :bar)
> *package* ;in bar
> 
> (in-package :cl-user)
> *package* ;in common-lisp-user
> 

Well, I pasted this code into bar.lisp, fired up CLISP from ILISP,
hit C-c C-l to load it, then moved point to the first *package*
form, hit C-c C-n, and the output window printed <CL-USER> package.

So, I think you're right, there must me something in my .emacs
or one of my ilisp configuration variables which screws up.

Now that you've all convinced me it _ought_ to work, I'll debug
it and report it to the list.  Thanks.

-- 
It would be difficult to construe        Larry Wall, in  article
this as a feature.			 <·····················@netlabs.com>
From: Gabe Garza
Subject: Re: ilisp and (in-package ...)
Date: 
Message-ID: <d72krf1f.fsf@kynopolis.org>
Johan Ur Riise <·@rsc.no> writes:

> This puzzles me.
> When type (in-package :unix) in the inferior lisp buffer
> (buffer *cmulisp* in my case), and then evaluate *package*
> in the sam buffer, it says package unix as expected.
> 
> But when I try to do the same in a normal ilisp buffer
> (M-x lisp-mode), sometimes the in-package form works, sometimes
> not. I use C-c n to evaluate the two forms in an ilisp-buffer.
> 
> Is this normal?

  Yes. :)

What I suspect you really want to know is a way of setting *PACKAGE*
from within ilisp.  You do this by using [C-z P] and [C-z p].

[C-z P] sets *PACKAGE* in the inferior lisp the package of whatever buffer
you're editing (it figures this out by scanning for an IN-PACKAGE form
in the buffer.

[C-z p] has it re-scan the buffer to figure out what package it should
be in (but doesn't change *PACKAGE*).

ilisp records the package for each buffer so you can work on a buffer
whose content belongs in a different package then *PACKAGE*.  If it
didn't, you'd have to remember to switch *PACKAGE* to the buffer's
package or risk messing up your namespace/having non-exported symbols
be undefined--general pandemonium.

The reason that having ilisp evaluate an IN-PACKAGE form fails when
you evaluate it from a buffer is that ilisp switches *PACKAGE* to the
package of the buffer, evaluates the form (which possibly changes
*PACKAGE*) and then changes *PACKAGE* back.  

To summarize: change *PACKAGE* from ilisp by first typing [C-z p]
and then [C-z P]

Gabe Garza