Re: A Question about DEFPACKAGE syntax
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Fri, 28 Dec 2007 17:57:09 +0100
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/
.
- Follow-Ups:
- Re: A Question about DEFPACKAGE syntax
- From: mathrick
- Re: A Question about DEFPACKAGE syntax
- From: Robert Uhl
- Re: A Question about DEFPACKAGE syntax
- From: Andreas Davour
- Re: A Question about DEFPACKAGE syntax
- References:
- Re: A Question about DEFPACKAGE syntax
- From: Dan Bensen
- Re: A Question about DEFPACKAGE syntax
- From: Pascal Costanza
- Re: A Question about DEFPACKAGE syntax
- From: Rainer Joswig
- Re: A Question about DEFPACKAGE syntax
- From: Edi Weitz
- Re: A Question about DEFPACKAGE syntax
- Prev by Date: Seibel/define-binary-class & binary-types-0.xx
- Next by Date: Re: take a sequence of numbers 2 at a time, print numbers and their product?
- Previous by thread: Re: A Question about DEFPACKAGE syntax
- Next by thread: Re: A Question about DEFPACKAGE syntax
- Index(es):
Relevant Pages
|
|