Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In clojure, why does a block comment containing a url throw an exception?

Why does the following is not work? That is why does it throw an exception?:

(comment 

Replicate a Sequence
http://www.4clojure.com/problem/33

        (= (__ [1 2 3] 2) '(1 1 2 2 3 3))

)

Replace the url with another string and it seems to be ok.

(comment 

Replicate a Sequence
replace the url and all is well. why 

        (= (__ [1 2 3] 2) '(1 1 2 2 3 3))

)
like image 450
user193116 Avatar asked Aug 16 '12 14:08

user193116


1 Answers

Because the url is not a valid token:

Clojure> http://www.4clojure.com/problem/33
java.lang.RuntimeException: Invalid token: http://www.4clojure.com/problem/33

Whereas the other string you had can be read as Clojure forms:

Clojure> (quote (replace the url and all is well. why))
(replace the url and all is well. why)

That is, Clojure can't parse the first example, regardless of whether it's in a (comment ...).

For completeness, note that the url is fine with a ; comment:

Clojure> 3 ; http://www.4clojure.com/problem/33
3
like image 56
Matt Fenwick Avatar answered Oct 08 '22 08:10

Matt Fenwick