Strange behavior seen when ints have leading zeros

22 views
Skip to first unread message

Robert Campbell

unread,
Nov 12, 2009, 8:08:47 AM11/12/09
to clo...@googlegroups.com
C:\dev\clojure>java -cp clojure.jar clojure.lang.Repl
Clojure 1.1.0-alpha-SNAPSHOT
user=> (def grid1 [01 02 03 04 05 06 07])
#'user/grid1
user=> grid1
[1 2 3 4 5 6 7]
user=> (def grid2 [01 02 03 04 05 06 07 08])
java.lang.NumberFormatException: Invalid number: 08
java.lang.Exception: Unmatched delimiter: ]
java.lang.Exception: Unmatched delimiter: )
user=>

Why does Clojure hate 8's? :-)

Fogus

unread,
Nov 12, 2009, 8:36:02 AM11/12/09
to Clojure
> Why does Clojure hate 8's? :-)

It doesn't. By adding a leading zero you're telling Clojure that you
want octal numbers. There is no number 08 in octal, instead to write
the base-10 number 8 you would use 010 in octal.

-m

Robert Campbell

unread,
Nov 12, 2009, 8:38:00 AM11/12/09
to clo...@googlegroups.com
Oh, that's pretty neat. Thanks!
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Ramakrishnan Muthukrishnan

unread,
Nov 12, 2009, 8:24:37 AM11/12/09
to clo...@googlegroups.com
I guess that's because if you precede a number with 0, it is treated
as Octal numbers and there is no Octal 8. :-)

Just a guess. I may be wrong.

--
Ramakrishnan
Reply all
Reply to author
Forward
0 new messages