Re: A Question about DEFPACKAGE syntax



In article <uabnun9dh.fsf@xxxxxxxxxx>, Edi Weitz <spamtrap@xxxxxxxxxx>
wrote:

On Fri, 28 Dec 2007 11:21:58 +0100, Rainer Joswig <joswig@xxxxxxx> wrote:

With one exception: Those almost-Common-Lisps that have all symbols
in lower case and have a case sensitive and case preserving
reader. This is non-standard and I would not use it. Several people
advocate the use of #:my-package and #:my-symbol because it is then
possible to use one DEFPACKAGE declaration source code for Common
Lisp and for not-really-Common-Lisp (aka 'Modern Mode', ...). IMHO
this is |wrong| and should be |AVOIDED|.

As this started with a "newbie" question, I'd like to add my two
cents.

This is how it is always. Somebody asks a simple question and
then this is the start of a long thread... ;-)

(Disclaimer: I've never used a "modern mode" Lisp and I have
to intention to use one.)

Firstly, the two variants

(defpackage "FOO"
(:export "QUUX"))

and

(defpackage :foo
(:export :quux))

are both legal ANSI Common Lisp and every CL implementation should
understand them. However, the first version is harder to type and
looks clumsy and old-fashioned. Granted, the second reason is
subjective and maybe that's just my bad taste, but you can't argue
that it's easier to type :foo than to type "FOO".

So, if I read someone's Lisp code and I see something like

(defpackage "FOO"
(:export "QUUX"))

then I usually think that the author doesn't know about the :foo
variant, or that for some strange reason he LIKES UPPERCASE LETTERS,
/or/ that he has a political agenda and explicitely wants to exclude
users of "modern mode" from his code. Whatever the reason is, I don't
see why this should be recommended to newcomers.

My 'technical' reasons:

* "FOO" does not create superficial symbols in the keyword package

* "FOO" stands out in text. It is easy to spot.

* "FOO" is robust against read-table changes. "FOO" stays uppercase.
:foo might be interned as lowercase.

I like to be more precise than with :foo .

Sometimes I mean lower or mixed case.
Then I also write "Foo" or "foo".

* Since some of the DEFPACKAGE forms get created and processed
by other (editor) tools, the tools generate/use the precise case
by writing/reading the symbol and package names as strings.

For example there are editor commands that down- or upcase
Lisp code (not just text, but takes care of strings, symbols,
comments, etc. ). I use stuff like that and want certain things
not to be downcased or upcased.

* Most Lisp functions print package and symbol names in uppercase.
Should I downcase and 'keywordify' them if I generate code?

In Lisp code is often not written but generated. I try to
be a bit in line with what the machinery uses and creates.
Hey, I could be using a lowercase, case-significant Algol
syntax, But I'm not. Not because Lisp is easier to type.

But because Lisp is easier to process.


More cultural:

* many tools (inspector, debugger, pretty printer, grinder, ...)
will show uppercase symbols and uppercase symbol names.
So my textual representation does not look different.
:foo is just an illusion. Once the form is read it is no longer
there. The symbol / package name is looking differently
internally when inspected.

* Angst: PACKAGE stuff is a horror. Many who have tried to
use or maintain complex package hierarchies should
have had problems with name clashes, weird import errors,
locked packages, etc. - thus I try to code as defensively
as possible when it comes to packages.



As for using #:foo instead of :foo to avoid cluttering up the keyword
package, I used to care but don't do that anymore. Nowadays, I mostly
use :foo simply because it is one character less to type and because
it looks better IMHO.

That's a matter of taste. For :keywords are something special.
They are unique identifiers, possibly associated with a value.
If I see them 'misused' for other purposes - for example
to denote package names and symbol names - it hurts my eyes.



Edi.

--
http://lispm.dyndns.org/
.



Relevant Pages

  • Re: access closure variable
    ... (lambda (command &optional args) ... Keywords are not really package independent. ... :FOO ... The reader will read:foo as a symbol in the keyword package. ...
    (comp.lang.lisp)
  • Re: Request for help constructing a simple macro
    ... Isn't an unbound symbol just a `symbol object'? ... Object in Lisp means generally all Lisp data. ... #:FOO ... No package for this symbol. ...
    (comp.lang.lisp)
  • Re: A Question about DEFPACKAGE syntax
    ... you give is a reason NOT to use strings. ... "FOO" does not create superficial symbols in the keyword package ... not creating those extra few symbols in the KEYWORD package is ...
    (comp.lang.lisp)
  • Re: Simple noob question.
    ... (setq key "foo") ... btw, I am thinking classic Lisp, if you have a case sensitive Lisp, uh, ... :foo but just note that it would be diff than:FOO. ... In general you can create a symbol using (intern string [package]), where if you omit the package it defaults to the current package (which can be determined by looking at the special variable *package*. ...
    (comp.lang.lisp)
  • Re: Problem comparing symbols
    ... Since you have used three symbols not in the CL package ... CL-USER 1> ... symbols that you use as tags go in the keyword package. ... CL-USER> (foo:hello 'greetings) ...
    (comp.lang.lisp)