Hex literals

29 views
Skip to first unread message

Jim Menard

unread,
Oct 5, 2008, 4:52:37 PM10/5/08
to clo...@googlegroups.com
In the section on literals at http://clojure.org/reader, it says,
"Numbers - as per Java, plus ..."

This implies to me that hex numbers like 0xff should be accepted by
the reader, but they are not. Is this a bug or a misunderstanding on
my part?

Jim
--
Jim Menard, ji...@io.com, jim.m...@gmail.com
http://www.io.com/~jimm/

Vincent Foley

unread,
Oct 5, 2008, 6:50:07 PM10/5/08
to Clojure
They seem to work fine with me:

user=> 0xff
255
user=> (+ 0xff 45)
300


On Oct 5, 4:52 pm, "Jim Menard" <jim.men...@gmail.com> wrote:
> In the section on literals athttp://clojure.org/reader, it says,
> "Numbers - as per Java, plus ..."
>
> This implies to me that hex numbers like 0xff should be accepted by
> the reader, but they are not. Is this a bug or a misunderstanding on
> my part?
>
> Jim
> --
> Jim Menard, j...@io.com, jim.men...@gmail.comhttp://www.io.com/~jimm/

Jim Menard

unread,
Oct 5, 2008, 8:04:32 PM10/5/08
to clo...@googlegroups.com
nimbus:/usr/local/src/Lisp/clojure> clojure
Clojure
user=> 0xff
java.lang.IllegalArgumentException: Invalid number: 0xff
java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
at clojure.lang.LispReader.read(LispReader.java:160)
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.IllegalArgumentException: Invalid number: 0xff
at clojure.lang.LispReader.readNumber(LispReader.java:198)
at clojure.lang.LispReader.read(LispReader.java:117)
... 6 more

I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
version of Clojure I am using from the command line, but I believe I'm
using the latest version 20080916.

Jim

--

Tom Emerson

unread,
Oct 5, 2008, 8:48:59 PM10/5/08
to clo...@googlegroups.com
FWIW,

The-Scrapyard (0)% java -cp clojure.jar clojure.lang.Repl
Clojure


user=> 0xff
255
user=> (+ 0xff 45)
300

user=> ^D
The-Scrapyard (0)% java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-241)
Java HotSpot(TM) Client VM (build 1.5.0_13-121, mixed mode, sharing)

This on a TiBook, Mac OS X 10.4.11 with Clojure 20080916 and svn 1051.

-tree

--
Tom Emerson
trem...@gmail.com
http://www.dreamersrealm.net/~tree

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.
Perhaps you're using that version?

I don't know how you tell what version of clojure you're using, but if you run:

jar tvf clojure.jar

all the files should have timestamps in September (mostly the 16th.)

--
Michael Wood <esio...@gmail.com>

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.

Michael Wood

unread,
Oct 6, 2008, 2:40:04 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <jim.m...@gmail.com> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
> at clojure.lang.LispReader.read(LispReader.java:160)
> 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.IllegalArgumentException: Invalid number: 0xff
> at clojure.lang.LispReader.readNumber(LispReader.java:198)
> at clojure.lang.LispReader.read(LispReader.java:117)
> ... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.

Jim Menard

unread,
Oct 6, 2008, 8:27:53 AM10/6/08
to clo...@googlegroups.com
On Mon, Oct 6, 2008 at 2:40 AM, Michael Wood <esio...@gmail.com> wrote:

> The previous release (from June) did not support hexadecimal numbers.
> Perhaps you're using that version?

You are correct; the files in my clojure.jar were all dated June 12,
2008. After downloading the latest version, all is well. Thank you for
your help.

> I don't know how you tell what version of clojure you're using, but if you run:
>
> jar tvf clojure.jar
>
> all the files should have timestamps in September (mostly the 16th.)

Perhaps a "--version" command line flag would be helpful.

Jim

Reply all
Reply to author
Forward
0 new messages