Bug: in-ns

5 views
Skip to first unread message

Ben Kearns

unread,
Sep 10, 2008, 5:37:51 PM9/10/08
to clo...@googlegroups.com
First off, great language. I've not posted before but
have been lurking a while and was at one of Rich's talks in NY a while back.
I'm still getting my head around what is and isn't allowed in the
language and ran across what I think is a bug either in my thinking or
in the reader.

user=> (in-ns 'foo)
(in-ns 'foo)
#<Namespace: foo>

user=> (in-ns '1foo)
(in-ns '1foo)
java.lang.NumberFormatException: Invalid number: 1foo
java.lang.Exception: ReaderError:(7,1) Invalid number: 1foo
at clojure.lang.LispReader.read(LispReader.java:163)
at clojure.lang.Repl.main(Repl.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.NumberFormatException: Invalid number: 1foo
at clojure.lang.LispReader.readNumber(LispReader.java:201)
at clojure.lang.LispReader.read(LispReader.java:120)
at clojure.lang.LispReader$WrappingReader.invoke(LispReader.java:440)
at clojure.lang.LispReader.readDelimitedList(LispReader.java:854)
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:783)
at clojure.lang.LispReader.read(LispReader.java:129)
... 6 more

Is there some reason that this is disallowed and should be avoided?

Thanks.

-b

Stephen C. Gilardi

unread,
Sep 10, 2008, 5:48:59 PM9/10/08
to clo...@googlegroups.com
On Sep 10, 2008, at 5:37 PM, Ben Kearns wrote:

user=> (in-ns '1foo)
(in-ns '1foo)
java.lang.NumberFormatException: Invalid number: 1foo

Is there some reason that this is disallowed and should be avoided?

Yes, the argument to in-ns is a symbol and symbol names cannot begin with a number. The reader will try to interpret a token that begins with a number as a number.

Please see http://clojure.org/reader , Reader Forms, Symbol which includes:

Symbols begin with a non-numeric character [...]

--Steve

Ben Kearns

unread,
Sep 10, 2008, 6:17:41 PM9/10/08
to clo...@googlegroups.com
Thanks. I missed that when I was reading the reader documentation.
Reply all
Reply to author
Forward
0 new messages