Subject: [clisp-list] problems with packages

From: Adam <[email-masked]>
Date: Tue Dec 11 06:28:03 2001

I recently upgraded clisp to 2.27, from FreeBSD ports.  I'm not sure the 
previous version, but the package was dated 2000.03.06.  I'm still 
fairly new to lisp, so I may be missing some basic ideas here.

I'm using le-sursis as an html-generating library, but with the upgrade 
it's failing to work.  Here is the top of sursis-html.lsp:

(in-package 'sursis-html :use 'common-lisp)
(defpackage sursis-html
   (:use common-lisp)
   (:nicknames s-html)
   (:export sa-tag tag http-response html head title body p h1 h2 h3 h4
            h5 h6 b i tt center blockquote pre img br hr a anchor ol ul
            li dl dt dd table tr td comment))

The first error I get is
[22]> (load "sursis-html.lsp")
*** - IN-PACKAGE: argument 'SURSIS-HTML should be a string or a symbol

So I change the first line to
(in-package :sursis-html :use :common-lisp)

Now I get
[23]> (load "sursis-html.lsp")
*** - There is no package with name "SURSIS-HTML"

So I move the in-package below the defpackage.

Now I can load the package, and access it with explicit names, like 
(s-html:head), but I want it in my namespace. For some reason, using the 
symbol works here, but I get a big list of name conflicts:
[24]> (use-package 's-html)
** - Continuable Error
35 name conflicts while executing USE-PACKAGE of (#<PACKAGE 
SURSIS-HTML>) into package #<PACKAGE COMMON-LISP-USER>.
1. Break [25]>
which symbol with name "P" should be accessible in #<PACKAGE 
COMMON-LISP-USER> ?
Please choose:
           1  --  SURSIS-HTML
           2  --  COMMON-LISP-USER

And so on for all the exported symbols.  But if I choose #2 (or run 
clisp again)
[26]> (p)
*** - EVAL: the function P is undefined
[27]> p
*** - EVAL: variable P has no value

I looked through the changelog, but didn't find anything.  Can someone 
enlighten me?

Thanks
Adam

---

From: Sam Steingold <[email-masked]>
Date: Tue Dec 11 07:30:02 2001

> * In message <[email-masked]>
> * On the subject of "[clisp-list] problems with packages"
> * Sent on Tue, 11 Dec 2001 06:26:32 -0800
> * Honorable Adam <[email-masked]> writes:
>

this is a cltl1 form.
see CLHS <http://www.lisp.org/HyperSpec/Body/mac_in-package.html>

> So I move the in-package below the defpackage.

good.

> And so on for all the exported symbols.  But if I choose #2 (or run

you should have chosen #1.

okay, the short answer is that you should read a Lisp book (e.g., Paul
Graham's "ANSI CL").

a longer answer is that when CL sees the DEFPACKAGE form, it is in the
COMMON-LISP-USER package, so the :EXPORT args are read and interned
there.  (_before_ being interened and exported from SURSIS-HTML).
Thus conflicts.

TRT is _not_ to use plain symbols before the IN-PACKAGE form, unless you
do know what and why you are doing (and the rule is -- you never need
this).  Use strings, keywords or uninterned symbols.  I recommend
strings since they create least garbage.

So I would re-write the preamble as follows:

(defpackage "SURSIS-HTML"
    (:use "COMMON-LISP")
    (:nicknames "S-HTML")
    (:export "SA-TAG" "TAG" "HTTP-RESPONSE" "HTML" "HEAD" "TITLE" "BODY"
             "P" "H1" "H2" "H3" "H4" "H5" "H6" "B" "I" "TT" "CENTER"
             "BLOCKQUOTE" "PRE" "IMG" "BR" "HR" "A" "ANCHOR" "OL" "UL"
             "LI" "DL" "DT" "DD" "TABLE" "TR" "TD" "COMMENT"))
(in-package "SURSIS-HTML")

An alternative is:

(defpackage "SURSIS-HTML" (:use "COMMON-LISP") (:nicknames "S-HTML"))
(in-package "SURSIS-HTML")
(export '(sa-tag tag http-response html head title body p h1 h2 h3 h4
          h5 h6 b i tt center blockquote pre img br hr a anchor ol ul
          li dl dt dd table tr td comment))

the "preferred ANSI way" is to collect everything in the DEFPACKAGE
form, as in my first example.

-- 
Sam Steingold (http://www.podval.org/~sds)
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
Someone has changed your life.  Save? (y/n)