Curious behavior of syntax quote?

55 views
Skip to first unread message

Subhash Gopalakrishnan

unread,
Mar 25, 2015, 12:10:54 PM3/25/15
to clo...@googlegroups.com
I saw this curious behavior when I was playing with ` and '. Syntax quote returns 'Cons' if the list has more than one item:

user=> (type `(1))
clojure.lang.PersistentList
user=> (type `(1 2))
clojure.lang.Cons


As far as I can see (https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L839), this should be returning a PersistentList always. Can anyone throw some light on how and why a Cons is returned for certain lists?

TIA,
Subhash

Herwig Hochleitner

unread,
Mar 25, 2015, 2:13:16 PM3/25/15
to clo...@googlegroups.com
I've not dived deeply into it, but could this come from two lines above? https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L837

As to why: PersistentList can only be consed from another PersistentList, where as Cons can be consed from any ISeq. Relatedly, Cons is a bit lighter-weight, since it  doesn't keep track of its count.

Reply all
Reply to author
Forward
0 new messages