From: Pascal J. Bourguignon on
jimka <jimka(a)rdrop.com> writes:

>> Does it make sense to separate 2 and 3? If they parse to they same
>> thing anyway, what's the point in having them reside in a separate
>> package?
>>
>
> It is a little bit hard to think about this abstractly I suppose. A
> real example would certainly help; I agree.
>
> There is no reason that I know of why a symbol cannot exist in
> multiple
> packages without loosing identity. If package A "uses" package B, I
> would expect the common symbols to be identical. At least A::foo and
> B::foo would refer to the same object. right?

Yes. And keywords are nothing special with this fourth property.

(import ':for)
(eq 'for :for) --> T


>> My impression is just that it is unclear _what_
>> you are trying to achieve.
>
> Sorry, but i'm not really at liberty to explain what I'm trying to
> achieve,
> but that should not be necessary in order to understand why certain
> choices
> were made in the CL specification.

Practicality!

Just try to write a program without keywords. When you'll be fed up
with collisions or fully qualified symbols for keyword parameters, you
might again invent keywords, with the same properties, because this is
what you need to make them practical.


>> Or, to put it differently, if you have a
>> different behavior (which you would have to specify), what would be
>> the advantage? Speculating about "why X" is useless, unless there is
>> an (implicit) comparison to some viable alternative.
>
> It is not that I necessarily want a differnt behavior. If someone
> is specifying a feature for lisp-foo, it is not really a sufficient
> argument to say, "You should do it like Common Lisp". But rather,
> "Common Lisp does it this way, and here is why...". Often the
> design choices in the CL spec are very well conceived, sometimes
> they are arbitrary, sometimes they are the lesser of two evils,
> and sometimes they are mistakes.

--
__Pascal Bourguignon__
From: Barry Margolin on
In article
<29f3dbaf-4a74-4fd0-9c71-0ec188d9976b(a)y17g2000yqd.googlegroups.com>,
jimka <jimka(a)rdrop.com> wrote:

> > 4. All keywords go into the same package. "KEYWORD". What causes the
> > evaluator to evaluate keywords to themselves? Is it that they exist
> > in this package? The CL syntax for keywords is that the a : preceed
> > the name. Other than this extremly handy syntax, is there any other
> > reason one might want all keywords in the same package? Is there an
> > reasonable argument to allow keywords in other packages? Restated,
> > suppose a lisp did not support the : synax for keywords but insisted
> > that keywords by identifyable by their inital character being "?".
> > Would their be an advantage for that lisp to force all such keywords
> > into the same package?
> >
> > -jim
>
> It's obvious from the responses to this question that the question is
> not stated very well. :-( Let me retry.
>
> Common lisp, keywords happen to have three very useful properties.
> 1. they always evaluate to themselves
> 2. they always parse to the same symbol, regardless of the value of
> *current-package*
> 3. key all have (are in) the same package: "KEYWORD"
>
> These three properties are really orthogonal, but is it nice the CL
> makes
> sure they are all true simultaneously

It's important for the way that keywords are intended to be used. The
simplest example is keyword arguments to functions: you want them to be
recognized regardless of the package that the caller is written in.

The alternatives would be to export the symbols, require the caller to
import them, or access them using :: syntax. These would either make
the syntax more verbose, or clutter up the namespace. Importing them
would likely result in lots of name conflicts.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal Costanza on
On 25/04/2010 18:58, jimka wrote:
> On Apr 25, 6:01 pm, p...(a)informatimago.com (Pascal J. Bourguignon)
> wrote:
>> jimka<ji...(a)rdrop.com> writes:
>>> 4. All keywords go into the same package. "KEYWORD". What causes the
>>> evaluator to evaluate keywords to themselves? Is it that they exist
>>> in this package? The CL syntax for keywords is that the a : preceed
>>> the name. Other than this extremly handy syntax, is there any other
>>> reason one might want all keywords in the same package?
>>
>> (eq ':x ':x) --> true is a good reason.
>>
>
> Maybe there is somthing fundamental that I misunderstand about CL
> packages.
> Isn't it possible for symbols in two pacakges to be eq? Isn't this
> what the :use keyword does on defpackage? It assures you that the
> symbols with the same name are eq.

Yes, but this can never happen by accident, you always have to ask for
this explicitly. Packages make it harder to have accidental nameclashes,
at the expense of having to invest some time and effort to properly
define your package relationships.

Keywords exists for symbols where you effectively don't care in what
package they are and want an easier way to have them without going
through all the bookkeeping that you need to do for other symbols.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: RG on
In article <rNOSPAMon-C5129C.07425925042010(a)news.albasani.net>,
RG <rNOSPAMon(a)flownet.com> wrote:

> It is universal practice in CL implementations to not only set the
> symbol-value of keywords to themselves, but also to define them as
> constants. One could reasonably argue that that this is not conforming
> behavior, but one would be wasting one's time.

Actually, I was just flat-out wrong about this. The spec does specify
that keywords are constants, but that specification is well hidden.
It's in the definition of the keyword type.

rg
From: Captain Obvious on
R> Actually, I was just flat-out wrong about this. The spec does specify
R> that keywords are constants, but that specification is well hidden.
R> It's in the definition of the keyword type.

----
11.1.2.3.1 Interning a Symbol in the KEYWORD Package

The KEYWORD package is treated differently than other packages in that
special actions are taken when a symbol is interned in it. In particular,
when a symbol is interned in the KEYWORD package, it is automatically made
to be an external symbol and is automatically made to be a constant variable
with itself as a value.
----