Newsgroups: comp.lang.lisp,comp.lang.lisp.x
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!tezcat!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!news.mathworks.com!uunet!in3.uu.net!192.35.48.11!hearst.acc.Virginia.EDU!murdoch!elvis.med.Virginia.EDU!sdm7g
From: "Steven D. Majewski" <sdm7g@Virginia.EDU>
Subject: Package Madness!  
X-Sender: sdm7g@elvis.med.Virginia.EDU
X-Nntp-Posting-Host: elvis.med.virginia.edu
Content-Type: TEXT/PLAIN; charset=US-ASCII
Message-ID: <Pine.A32.3.93.970108124420.22966A-100000@elvis.med.Virginia.EDU>
To: Xlisp List <stat-lisp-news@umnstat.stat.umn.edu>
Followup-To: comp.lang.lisp
Sender: usenet@murdoch.acc.Virginia.EDU
Organization: University of Virginia
Mime-Version: 1.0
Date: Wed, 8 Jan 1997 18:41:28 GMT
Lines: 143
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:24514 comp.lang.lisp.x:1872


I had quite a few problems mastering the intricacies of Lisp 
Packages -- particularly when they involve using packages to
redefine and shadow existing functions, until I discovered
( in CLtL1 ) the mnemonic "Put in seven extremely random 
interface commands" - which corresponds to the  sequence:
	Provide
	IN-package
	Shadow
	EXport
	Require
	USE-package
	Import
	Commands==Contents of package/module

Which is the order you (mostly) have to use those statements to
be able to Require your package without tripping over any name
clashes. ( Actually, I've been sticking "Provide" at the *end*
of my packages so that if it is provided, that indicates that 
it did load successfully. That shouldn't make any difference with
a well tested module, but it helps with something that I'm 
interactively editing and testing. If PROVIDE executes and *then* 
the module bombs out, I have to manually LOAD the module before
reloading the module which REQUIREd it. ) 


That technique has mostly worked for me, however, I have still 
seen some dependencies on the order in which my modules are 
loaded. I ignored or worked around most of these glitches until
I was trying to compile some of the more finished modules and 
save them into my workspace. 

I found that some of the name clashes had to do with using a 
symbol in a non defining position, such as an argument list. 

These problems were with XlispStat 3.47 ( for the Macintosh ). 
Since Xlisp is not quite Common Lisp -- it includes a lot of
functions for Common Lisp compatibility, but things like packages
and symbol binding are where I would suspect the most compatibility
problems -- I also tried simulating a similar case in KCL ( the 
particular code where I noticed the problem had too many XlispStat
and intermodule dependencies for me to easily load that code ),
and I get a similar error. 


The two sessions below both generate errors from a name conflict
on the symbol 'SEQ. In both, SEQ is defined and exported in 
package "X". In the first case, #'SEQ is used in a definition
before the ( USE-PACKAGE "X" ) statement. In the second, SEQ
is merely used in the argument list in defining another function. 
 This is basically the same cases that are generating my errors
in XlispStat, although the exact error message is slight different.
It's basically the same error. On both systems, ( FIND-SYMBOL "SEQ" )
returns NIL before the use of the symbol in the USER package, and
returns the values SEQ, :INTERNAL after it's use. 
( The only significant difference I've noticed is that in some cases,
  the symbol XlispStat complains about is :SEQ -- presumably in the
  keyword package, even thought the string ":SEQ" is never used in 
  my code. ) 


 *  Am I doing something wrong here ? 

 *  Is this error normal Lisp behavior for other implementations 
    or is this behavior according to Common Lisp standard ? 

  [ And if it *is* normal or standard, isn't it terribly inconvenient? 
    ( I can swallow the first case, but the second being an error
      is pretty extreme! ) 
    I have been finding Lisp packages a horribly intricate maze 
    compared to the simple module system in Python. ( I haven't 
    yet tried to do anything complex in Java, so I can't contrast
    its packages. ) ] 


$ kcl
AKCL (Austin Kyoto Common Lisp)  Version(1.505) Sat Dec 22 02:25:20 EST  1990
Contains Enhancements by W. Schelter
Changes in version 1-455 definitely require recompilation of user files.

>( defun a () ( seq a ))
A
>( setf a ( list 1 2 3 4 ))
(1 2 3 4)
>( make-package "X" )
#<"X" package>
>( in-package "X" )
#<"X" package>
X>( EXPORT '( SEQ ))
T
X>( defun seq ( &rest args ) args )
SEQ
X>( in-package "USER" )
#<"USER" package>
>( use-package "X" )

Error: Cannot use #<"X" package>
       from #<"USER" package>,
       because X:SEQ and SEQ will cause
       a name conflict.
Error signalled by USE-PACKAGE.

Broken at USE-PACKAGE.  Type :H for Help.
>>



AKCL (Austin Kyoto Common Lisp)  Version(1.505) Sat Dec 22 02:25:20 EST
1990
Contains Enhancements by W. Schelter
Changes in version 1-455 definitely require recompilation of user files.

>( defun MOST ( &rest seq ) ( cdr seq ))
MOST
>( make-package "X" )
#<"X" package>
>( in-package "X" )
#<"X" package>
X>( export '( seq ))
T
X>( defun seq ( &rest args ) args )
SEQ
X>( in-package "USER" )
#<"USER" package>
>( use-package "X" )

Error: Cannot use #<"X" package>
       from #<"USER" package>,
       because X:SEQ and SEQ will cause
       a name conflict.
Error signalled by USE-PACKAGE.

Broken at USE-PACKAGE.  Type :H for Help.



---|  Steven D. Majewski   (804-982-0831)  <sdm7g@Virginia.EDU>  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of Virginia             Health Sciences Center  |---
---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---
         By doing just a little every day, you can gradually 
                let the task completely overwhelm you.

