expected treatment of backslash in string literal

964 views
Skip to first unread message

.Bill Smith

unread,
Nov 3, 2007, 11:20:26 PM11/3/07
to Clojure
Clojure rejects putting a backslash before a period in a string
literal. Is that the expected behavior?

user=> (seq (. "this.is.a.test" (split "."))) ;;expected
nil
user=> (seq (.. "this.is.a.test" (replace "." "_") (split
"_"))) ;;expected
("this" "is" "a" "test")
user=> (seq (. "this.is.a.test" (split "\."))) ;;huh?
java.lang.Exception: ReaderError:(180,1) Unsupported escape character:
\.
at clojure.lang.LispReader.read(LispReader.java:145)
at clojure.lang.Compiler.main(Compiler.java:2806)
Caused by: java.lang.Exception: Unsupported escape character: \.
at clojure.lang.LispReader$StringReader.invoke(LispReader.java:281)
at clojure.lang.LispReader.readDelimitedList(LispReader.java:608)
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:545)
at clojure.lang.LispReader.readDelimitedList(LispReader.java:608)
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:545)
at clojure.lang.LispReader.readDelimitedList(LispReader.java:608)
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:545)
at clojure.lang.LispReader.read(LispReader.java:111)
... 1 more
user=>

Thanks,
Bill Smith

Rich Hickey

unread,
Nov 6, 2007, 8:46:32 PM11/6/07
to Clojure

On Nov 3, 10:20 pm, ".Bill Smith" <william.m.sm...@gmail.com> wrote:
> Clojure rejects putting a backslash before a period in a string
> literal. Is that the expected behavior?

Yes. Backslash is an escaping character and . is not a valid escape
character. If you want a backslash in a string use 2 backslashes.

Reply all
Reply to author
Forward
0 new messages