Clojure – Are Square Brackets and Curly Braces S-Expressions?

clojurelisp

I am trying to learn Lisp and looking at all the Lisps out there and their differences.

I see that in some implementations of Scheme, you can use square brackets interchangeably with round brackets for readability, so because they are treated the same, I assume they are still just S-expressions like everything else.

However, in Clojure I see that square brackets and curly braces are used to represent different data types like vectors and so on. Are these also still valid S-expressions, or must they be considered atoms? Doesn't this "break" the whole concept of S-expressions, thereby making Clojure an "impure" Lisp?

Best Answer

Literal notation for vectors and maps (ie, square brackets and curly braces) are just read-time sugar, and anything you can represent with that notation can also be represented with S-expressions. As a result, there's no loss of power or homoiconicity, and indeed reader macros (which I understand are even more powerful) are available in a number of lisps.

Incidentally, note that Clojure now provides a mechanism for creating custom "tagged" literals, which, like other literals, are transformed to S-expressions before they are compiled and interpreted.

Related Topic