[Bug?] Keyword constraints not enforced

94 views
Skip to first unread message

smf...@googlemail.com

unread,
Nov 23, 2008, 6:38:16 AM11/23/08
to Clojure
Hi,

According to http://clojure.org/reader:

> Keywords are like symbols, except:
>
> o They can and must begin with a colon, e.g. :fred.
> o They cannot contain '.' or name classes.

This is what I get using the latest SVN revision (1211):

user=> (keyword? :String)
true
user=> (keyword? :a.b.c)
true
user=> (keyword? :java.lang.Integer)
true
user=>

Shouldn't this throw an exception? It seems that keywords aren't
checked for correctness at all right now.

James Reeves

unread,
Nov 23, 2008, 9:09:17 AM11/23/08
to Clojure


On Nov 23, 11:38 am, "smf...@googlemail.com" <smf...@googlemail.com>
wrote:
> Hi,
>
> According tohttp://clojure.org/reader:
>
> > Keywords are like symbols, except:
>
> >          o They can and must begin with a colon, e.g. :fred.
> >          o They cannot contain '.' or name classes.
>
> Shouldn't this throw an exception? It seems that keywords aren't
> checked for correctness at all right now.

I'd like to request that keywords continue to allow the '.' character,
as it's useful for certain edge cases (Compojure and clj-html use it
to specify class attributes, for instance). Does the inclusion of a
'.' in a keyword introduce any syntax ambiguity I'm unaware of?

Disallowing class names in keywords seems a little odd too, especially
with AOT. If you compiled a Clojure file like clojure.contrib.def,
would that mean you'd lose the ability to use the keyword :def?

- James

Rich Hickey

unread,
Nov 24, 2008, 9:26:54 AM11/24/08
to Clojure
I think you've both misread "they cannot name classes" to be - "They
cannot contain class names".

The symbol String can name a class but the keyword :String can't,
that's all I meant there.

As far as '.', that restriction has been relaxed. I'll try to touch up
the docs for the next release.

Rich

kwatford

unread,
Nov 25, 2008, 5:08:29 PM11/25/08
to Clojure
Somewhat related, I noticed that the keyword function doesn't seem to
make any attempt at ensuring keywords are even readable.

user=> (keyword "(foo)")
:(foo)

Is this intended?

James Reeves

unread,
Nov 25, 2008, 7:29:59 PM11/25/08
to Clojure
On Nov 24, 2:26 pm, Rich Hickey <richhic...@gmail.com> wrote:
> I think you've both misread "they cannot name classes" to be - "They
> cannot contain class names".
>
> The symbol String can name a class but the keyword :String can't,
> that's all I meant there.

Ah, I get it now.

> As far as '.', that restriction has been relaxed. I'll try to touch up
> the docs for the next release.

Thanks!

- James
Reply all
Reply to author
Forward
0 new messages