Punctuation is not syntax. Lisp can be said to have a syntax, that of
the S-Expression. Beyond that, as someone else pointed out in another
thread here recently, when we write Lisp code, we're basically writing
directly the AST that other languages would need a parser implementing
a complicated grammar to produce.
> Next is the single quote, which is just an alias for quote.
> Somewhere along the line, someone decided that (quote foo) was too
> verbose and they wanted 'foo to be syntactic sugar for (quote foo).
> That wasn't and can't be done as a macro. For example, if I wanted
> to define my own single quote, say $foo, I can't without modifying
> the parser.
>
> Clojure goes on to add a lot of syntax. The literal syntax for
> vectors [], maps {}, sets #{}, functions #(), keywords :, etc. are
> all syntax, not possible with macros, and then there are all the
> "reader macros" that are listed in Section 2.2, Comment ;, Deref @,
> Meta ^, Metadata #^, regex #"", syntax-quote `, unquote ~,
> unquote-splicing ~@, and var-quote #'.
All these things are syntactic sugar. Shorthand ways to write things
that have vanilla S-Expression counterparts. Again, I would not call
them syntax.
> So is it really valid to claim Clojure has no syntax?
Very nearly so.
Randall Schulz
Thanks. You forced me to look up the reference to which I alluded:
On Thursday 11 December 2008 06:32, evins...@gmail.com wrote:
> Subject: Re: In core structure editor, anyone?
>
> Structure editors are not in common use, maybe because, while they're
> a valid and maybe cool alternative to text editors for lisp code,
> it's not clear how useful they are for other kinds of code. In most
> programming languages a lexer and parser construct an abstract syntax
> tree from the source code. In lisp, the abstract syntax tree *is* the
> source code. That being the case, it makes a lot of sense with lisp
> to operate directly on the parse tree. In other languages, not so
> much.
So the kudos go to Mikel Evins (or is it Evins Mikel?).
Randall Schulz
Well said, and I need to find a place to make this explanation in the
book prior to chapter 7. :-)
Stuart
I have to say "no."
Syntax is about complex ordering rules. Take a look at the grammar for
Java or C or Pascal or Ada or even for YACC or JavaCC! They're
horrendously complicated. There's nothing like that in Lisps.
Syntactic sugar of the sort present in Lisps is very simple. One or two
characters trigger a small modification or adornment of what
immediately follows.
A more interesting contrast, perhaps, is CLIF, the Common Logic
Interchange Format (successor to KIF). If I flashed a page of it in
front of you, you'd think it was Lisp. It uses prefix, fully
parenthesized notation. But it requires a grammar specified in BNF.
So you _can_ have syntax in such notational forms, but Lisp doesn't
Randall Schulz
I think that depends on which particular nits are being picked.
Is it strictly true that Clojure has "no syntax"? Meh--probably not.
(defun foo [bar] ...) has more unique characters than (defun foo (bar) ...) or (define (foo bar) ...) but is it a *meaningful* difference?
Is '(foo) meaningfully different than (quote (foo))? Again, more unique characters... but is it in the language, or is it in the reader? They're called reader macros for a reason.
All in all, not something I'll be terribly concerned with either way.
Dave
Given that function definitions are closed, it's eminently feasible for
an editor to detect whether a calling form is valid or not. Keep in
mind that the only kind of function overloading in Clojure is that
based on arity.
More complex forms of overloading require the use of multimethods, which
do their dispatching dynamically and arbitrarily based on the supplied
arguments (dynamically). In that case, not all calling forms will be
statically validateable, though some still will.
> --Dave Griffith
Randall Schulz
>> Clojure goes on to add a lot of syntax. The literal syntax for
>> vectors [], maps {}, sets #{}, functions #(), keywords :, etc. are
>> all syntax, not possible with macros, and then there are all the
>> "reader macros" that are listed in Section 2.2, Comment ;, Deref @,
>> Meta ^, Metadata #^, regex #"", syntax-quote `, unquote ~,
>> unquote-splicing ~@, and var-quote #'.
>
> All these things are syntactic sugar. Shorthand ways to write things
> that have vanilla S-Expression counterparts. Again, I would not call
> them syntax.
I really have trouble understanding the idea that punctuation and
syntactic sugar shouldn't be considered syntax. To me, syntax is
anything that a human reader has to comprehend in order to understand
the structure of the code. I say "structure" because that excludes
having to understand what every function and macro does.
For example, it is very important for human readers of Clojure code to
understand that ^# adds the metadata that follows to the form that
follows that.
--
R. Mark Volkmann
Object Computing, Inc.
S-Expressions and its counterparts are technically a syntax. I guess
the distinction was made to stress that the Clojure's "syntax" is only
a small subset of what is called syntax in other languages - namely
data literals.
But then, I agree with you that any text format has associated syntax.
Just like XML or HTTP protocol do.
> To me, syntax is
> anything that a human reader has to comprehend in order to understand
> the structure of the code. I say "structure" because that excludes
> having to understand what every function and macro does.
The trick is that the source code is not really represents "code" at
all. It just a text description (literal) of ordinary Clojure data
that happen to describe the "code".
Regards,
-r.