(destructuring-bind (a b c) '(10 20 30) c)
? Destructuring is also supported in the LOOP macro (http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node252.html)I don't think this article was written for the non-users of Lisp, it uses too many advanced language features without any explanation to be accessible to non-Lispers.
Why c? Why the quote? Why not have elegant language syntax instead of that clunky macro?
The quote is a multi-purpose element of the syntax, unlike `[` in Python, which only serves a single purpose (actually, it doubles as an item getter syntax). Whether having a single, more universal construct which you can use in many situations, or having a few more specialized constructs is more elegant is debatable and I think a matter of taste.
The problem with having specialized syntax for this is that it's not extensible. For example, we (I'm a Python programmer, too) had to wait for 3.4 (IIRC) for a very simple feture of `a, b, *c = range(10)`; with a language built on macros you can extend these constructs as much as you wish. For example adding support for destructuring hash-maps (if it's not supported already) shouldn't be a big problem; on the other hand adding a specialized syntax for dict destructuring in Python is impossible within a language.
That does explain it very well but I'd also argue that a syntax that requires that much explaining probably can't be called "elegant".
Powerful though? Yes. Lips syntax certainly is that.
[a, b, c] = [10, 20, 30]
1 2 3 4 5 6 7 8 9
In Common Lisp, you an express that 10 20 30 should go to a b c using values: (setf (values a b c) (values 10 2 30))
That still has fewer overhead tokens! (setf (values a b c) (values 10 2 30))
1 2 3 4 5 6 78
If they are bother make yourself (vsetf (a b c) (10 20 30))
This is easy to implement in a quick and dirty way: (defmacro vsetf (places exprs) `(psetf ,@(mapcan #'list places exprs))
(macroexpand-1 '(vsetf (a b c) (1 2 3)))
-> (PSETF A 1 B 2 C 3)
psetf is probably a good choice here since it is probably best for the construct to have parallel semantics. That is to say, we want, for instance, to be able to exchange variables with it: (vsetf (x y) (y x))
which will work thanks to psetf.We could huff and puff a little harder in the macro and make it work like
(vsetf x y = y x)I think his point was that Lisp pushes syntactic minimalism to an extreme, but all the complexity then gets shoved into what your keywords are doing. You're not eliminating complexity, you're just moving it somewhere else. Judicious introduction of syntax + keywords can be better than depending on magic keywords/macros/symbols alone.
A concrete example of this comes from math--while we could write every integral as
(Integral lbound ubound body differential)
I'd argue that our usual integral notation is both more readable and compact because the spatial positioning of the elements has semantic meaning.The tradeoff is as you introduce more syntax, it's harder to get a macro system as elegant as Lisp's; Lisp macros are relatively easy to write because s-exprs are simple. But we shouldn't pretend that there's no downside to a minimal syntax--otherwise we would all be coding in pure untyped lambda calculus or Brainfuck.
The ideal syntax for performing some operation O on entities X, Y and Z consists only of the symbols O, X, Y an Z. We need the parentheses to delimit that as an expression among other symbols.
That's simply begging the question.
That viewpoint only makes sense if all code is most parsimoniously broken down into its parse tree, but I don't think that's been shown.
When all you have is a hammer (even a slick, homoiconic hammer), everything looks like a nail.
> We need the parentheses to delimit that as an expression among other symbols.
There are other ways to delimit expressions as well (e.g. implicitly with precedence, with whitespace, with HTML tags, with curly braces, etc.); why is Lisp's way the one true way?
All modern console fonts for writing code are sans-serif.
(I'm using Microsoft's Consolas, even on GNU/Linux systems).
A number of times in the past I tried finding a serif font for editing code, just for shits and giggles. And, by golly, that's precisely all it was good for.
If you want squiggly high frequency noise in your code, you can just switch to that type of font; no need to foist that into the programming language.
For clarification, I wasn't suggesting to use serifs for coding. It's not necessary there, because it's not the letters themselves that need to catch the eye, but code structure. All those square and curly braces, commas etc do just that. As does indentation, but using indentation for everything, the way Lisp tends to do, blurs too many distinctions.
S-exprs are great for machines, just as binary is - it's simple and consistent and lacks pointless redundancy. But humans aren't machines - redundancy is good for us sometimes.
Non-sequitur - serifs are for small, black-on-white, type as visual hinting. You'd not expect serif type on road signs.
All you've done is demonstrate ignorance of typography
> TThat assignment has 9 pieces of extra syntax
Seeing as we're not playing Code Golf that does t really matter does it? What it is is clearer, easier to understand, and actually built into the language.
Lisp is many things, syntactically elegant isn't one of them.
I'm willing to try to put some kind of numbers on my point of view. Basically, it boils down to token counts and the presence of implicit associativity and precedence rules.
We can remove four square parentheses from the [ a, b, c ] = [ 1, 2, 3 ] assignment, thereby significantly reducing the verbiage. However, we end up with ambiguity. There is no universal precedence between comma and assignment. For instance, in C (a language which indirectly inspired the syntax of ES), it is the other way: the expression a, b, c = 1, 2, 3 in C will perform only the c = 1 assignment. It's good that ES spends these extra tokens to reduce ambiguity here.
Every extra token should count as one demerit point. Then, every instance in a sentence where an implicit rule must be invoked to disambiguate the parse should result in multiple demerits determined according to how the smallest number of grouping tokens would have to be inserted to remove the ambiguity. (That's being generous, because it doesn't take into account the work of determining the parse and doing the insertion.)
So for instance "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" has a minimal number of tokens to express its meaning (which is good), but there is a significant cognitive load to figure out its structure from all the implicit grammar rules (bad). If we insert the parentheses we get "((Buffalo buffalo) (Buffalo buffalo) buffalo) buffalo (Buffalo buffalo)".
Some functional languages have this "buffalo disease"; strings of words are just catenated, and working out all the partial applications that are buried in there and whatnot is a hairball.
That's... a really arbitrary and contrived presumption. Not to mention presuppositional (and circular) in nature. "I define what makes a language beautiful as what Lisp is best at, therefore lisp is most beautiful."
It's things like this which cause Lisp evangelists to not get taken seriously.
Based on your comparison anyhow Python is much better with it's Tuples (ie - a, b, c = 1, 2, 3) and lisp would be fundamentally worse.
Which you did. So you weren't.
(setf (values a b c)
(values 10 20 30)) a, b, c = 10, 20, 30 # let a, b, c = 10, 11, 22;;
val a : int = 10
val b : int = 11
val c : int = 22
# a, b, c;;
- : int * int * int = (10, 11, 22)
# (a, b, c);;
- : int * int * int = (10, 11, 22)It's ambiguous. What is the relative precedence of the comma and equal sign? You just have to know.
Lisp means never memorizing associativity and precedence tables again.
Why is that an unambiguous benefit though?
By that logic, we ought to have parentheses around every mathematical expression as well.
I think there's a sane middle ground between forcing people to memorize endless precedence tables versus not having any implicit precedence at all.
Yes we should. Some math notations are simply crazy; they make it hard to follow the semantics.
The one thing that turns me off math is the notation.
A lot of math papers don't explain their notation; that's another problem.
Good luck getting your lisp code merged with mismatched tabs/spaces or everything aligned to column 0.
Though realistically you're destructuring in the same way just with implicit vs explicit structure.
Practically speaking there's no difference but CL has a less clear syntax.
I think the 'which is clearer' thing is up to personal choice and experience. And personally, often when I'm programming in one not-Lisp, I'm often bitten by things which would have been explicit in Lisp, and the other way around - sometimes I really wish that different things looked different, as in Perl.
This is no exception.
From the first example on there is not one case where the Lisp syntax is a clearer expression of the concept and it's hard to justify that anything that is less clear is elegant in the slightest.
Personally I'd put destructing assignment as more elegant for the first example:
But that's just me.