Hacker News new | past | comments | ask | show | jobs | submit login

Clojure syntax is s-expressions, your own private definition notwithstanding.



> Clojure syntax is s-expressions

That can't be the case. Clojure provides 'special forms' and has macros. All those add syntax to the language.

The syntax of Clojure s-expressions is just that: the syntax of Clojure s-expressions - but not the syntax of the Clojure language.

The Clojure site says:

http://clojure.org/special_forms

    The syntax for function definitions becomes the following:

    (fn name? [params* ] condition-map? exprs*)
    (fn name? ([params* ] condition-map? exprs*)+)
Read the word syntax? See the EBNF like syntax descriptions with star, question mark and plus syntax operators? See parentheses structure with [] and () in the second example?

star -> zero or more expressions

plus -> one or more expressions

question mark -> one optional expression

That's syntax. It describes the structure of s-expressions which form valid Clojure code.

Not all Clojure s-expressions are valid Clojure code. There are lots of syntactic restrictions. See the syntax for 'fn' above for an example.

> your own private definition notwithstanding.

You may want to take over the Clojure.org site to follow your own, private, definition of Clojure syntax. Personally I prefer the usual definition of Clojure syntax, as for example shown on Clojure.org .

Claiming that Clojure only has s-expressions as syntax is thus wrong and misleading.


well I guess CL doesn't have s-exps either then who knew! https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node59.html


Of course Common Liep has s-expressions. Everybody knows that.

But s-expression syntax is not the complete syntax of Lisp programs. Lisp programs are written using s-expressions. But not every s-expression is a valid Lisp program. There is syntax for lambda expressions, various special forms and syntax implemented by macros.

S-expression syntax OTOH is only the syntax for, wait, s-expressions.

A Lisp compiler will check the syntax of Lisp code at compile time:

    * (defun foo () (let a ((b 10)) 3))
    ; in: DEFUN FOO
    ;     (LET A
    ;       ((B 10))
    ;       3)
    ; 
    ; caught ERROR:
    ;   Malformed LET bindings: A.
Here the syntax for LET is violated.

The syntax for LET is defined as:

    let ({var | (var [init-form])}*) declaration* form* => result*
Thus the compiler expects a list of bindings and not a symbol, as in my example above.

Every Lisp programmer will need to learn this syntax. Not just ATOM plus (S-EXPRESSION*).


I'm not really sure what your point here. These are implementation details of how CL works. Has nothing at all to do with what s-expressions are in principle.


I'm not sure why it's so difficult to understand for you.

S-expressions give us a textual syntax for data. But not for Lisp. Lisp syntax is built on top of s-expressions and has to be learned. That's true for Scheme, too. See chapter 7.1 of the Scheme R7RS specification: "Formal syntax". That's not s-expressions.

> I'm not really sure what your point here.

That seems to be a common theme for you. I'll help you out: Your original points were this:

> Clojure syntax is s-expressions, your own private definition notwithstanding.

Which I showed you by pointing to Clojure.org to be wrong. Clojure syntax is more than s-expressions.

> The syntax is very minimal and consistent while also extremely expressive.

This also is wrong, since the syntax consists of all kinds special forms and macros, too. The user can even introduce lots of new syntax by implementing it as macros. Every library with macros is likely introducing new syntax and semantics.


now explain how reader macros in CL fit into your argument :)


Isn't it obvious? Reader macros are in the first place there to implement and extend the s-expression reader. It implements parsing of the data structures: conses, lists, arrays, vectors, strings, symbols, various number types, bit vectors, ...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: