Brian Candler said:
Sure. But why would anyone want to write something like
a = b + c
when they could just as easily have written
(set!
(quote a)
(+ b c))
instead?
(Note: untested and probably wrong. I have a sneaking suspicion that
set! may be a special-form and so doesn't require its first argument to
be quoted.
In Scheme, there's no option. It's: (set! a (+ b c))
The point is that whatever the 'message' you 'send', whatever the
'function' you 'call', you always write it the same:
(<operator> <argument> <argument> ...)
This allow to process easily any expression, with no parsing, and with
no knownledge of the operators (and their arity or variable arity).
These expression can be processed by user code, by macros, (of course
by the scheme compilers), but also by trivial tools such as editors,
who need only to know how to count parentheses to correctly parse
lisp expressions.
That's the reason why, since Ruby has some lisp genes, and allows it,
I write my ruby code as:
(a = (b + c))
It's a little harder than in lisp, because you have strange rules and
exceptions, you have to put the first argument first instead of the
operator (while of all times, in maths you've learned to put the
operator first: f x, Σ n, etc).
But you can see that it's about he same form, and not more complex in
lisp than in ruby:
(a = (b + c))
(set! a (+ b c))
And this allows me to benefit from the structural editing functions of
my editor.
Unfortunately the similarties stop there, and when you need to do
metaprogramming in Ruby, you have to invoke complex parser packages,
and use barbaric syntaxes with a lot of useless characters such as:
[:=,:a,[:+,:b,:c]]
instead of the simply:
'(= a (+ b c))
or just:
'(set! a (+ b c))
It would not have costed anything to leave the quote operator alone...
Of course, there is no clue to this in the syntax, or lack of
it. That's also ignoring any differences between Scheme and LISP)
In the case of Common Lisp, you don't have "syntactic" clues pers se,
but there are naming conventions for the operators, (and otherwise not
being totally dumb, lisp programmers try to give meaningful names to
their functions to give enough hints), so you can know that:
(set (quote <symbol>) <expression>)
becomes as a shorthand:
(setq <symbol> <expression>) ; notice the q in setq, which
; stands for quote.
or the more modern:
(setf <place> <expression>) ; the f stands for form, since <place>
; can be (almost) any form.