27 Sep 2013, 19:29
Generic-user-small

Juan Manuel Gimeno Illa (4 posts)

You seem to imply that an s-expression only consists of lists of lists and vector literals are not s-exprs. For what I understand and S-expr is the representation the reader is capable of generating from the character stream in the input. In the case of traditional lisp, only atoms (numbers, symbols, etc.) and lists are allowed. In Clojure’s case, as there is a literal syntax for vectors and sets, the s-exprs are more sophisticated, but s-exprs as well.

27 Sep 2013, 22:03
Icon_pragsmall

Paul Butcher (25 posts)

Juan,

Thanks for taking the time to post.

I chose my wording carefully when I said “Clojure code is almost entirely constructed from parenthesized lists called s-expression”.

You’re quite right - vector literals are not s-expressions. As Rich Hickey says:

Clojure extends the code-as-data system beyond parenthesized lists (s-expressions) to vectors and maps. Thus vectors and maps can be used in macro syntax, have literal reader representations etc.

Clojure supports a wider range of syntax than most lisps through reader macros but these become s-expressions under the hood. For example I can define a vector like this:

user=> [1 2 3]
[1 2 3]

or with an s-expression:

user=> (vector 1 2 3)
[1 2 3]

The same is true for maps:

user=> {"foo" 1 "bar" 2}
{"foo" 1, "bar" 2}
user=> (hash-map "foo" 1 "bar" 2)
{"foo" 1, "bar" 2}
28 Sep 2013, 16:04
Generic-user-small

Juan Manuel Gimeno Illa (4 posts)

Maybe I’m wrong, but I think that in Clojure s-expressions must include literals for vectors, sets and maps. My reasoning is that, in Lisp, a s-expr is what the reader returns an in Clojure the reader can return vectors.

For instance:

(defmacro foo [expr] (vector? (second expr)))

expand differenty in (foo (1 [2 3] 4) and in (foo (1 (vector 2 3) 4)because the s-expr the reader returns are different.

If [2 3] was only syntactic sugar for (vector 2 3) the results should be the same.

I don’t know how the Clojure implementation works, but conceptually (at least for me) the literal syntax for vectors, sets and maps should be part of it.

Juan Manuel

28 Sep 2013, 17:10
Icon_pragsmall

Paul Butcher (25 posts)

I see your point Juan, but I’m unsure what to say beyond pointing you at the Rich Hickey quote in my answer above:

Clojure extends the code-as-data system beyond parenthesized lists (s-expressions) to vectors and maps. Thus vectors and maps can be used in macro syntax, have literal reader representations etc.

I interpret that as as saying that s-expressions are parenthesized lists, and vectors and maps are an extension beyond s-expressions?

28 Sep 2013, 18:22
Generic-user-small

Juan Manuel Gimeno Illa (4 posts)

I suppose s-expressions as nested lists has too much history baggage.

Thanks for your patience !!

Juan Manuel

  You must be logged in to comment