News for hackers. Stuff that matters.
Re:Playing with Syntax by abritinthebay on Saturday August 20, 2016 @12:35PM (#12327247)
Every Lisp article promoting the "elegance" of its syntax will do the exact opposite to non-users of Lisp.

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:

    [a, b, c] = [10, 20, 30]
But that's just me.
Re:Playing with Syntax by klibertp on Sunday August 21, 2016 @08:35AM (#12330698)
Wouldn't this work:

    (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.

Re:Playing with Syntax by abritinthebay on Sunday August 21, 2016 @12:51PM (#12331572)
Thats... similar but I wouldn't call it "more elegant". It's less clear in almost every way.

Why c? Why the quote? Why not have elegant language syntax instead of that clunky macro?

Re:Playing with Syntax by klibertp on Monday August 22, 2016 @04:11AM (#12334811)
I put `c` there because `destructuring-bind` is lexically scoped and only binds values to names inside of it. This may be a good or a bad thing, depending on your use case, but I prefer having the scopes clearly visible.

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.

Re:Playing with Syntax by abritinthebay on Wednesday August 24, 2016 @02:02PM (#12353950)
Good explaination! Thank you!

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.

Re:Playing with Syntax by kazinator on Saturday August 20, 2016 @12:49PM (#12327303)
That assignment has 9 pieces of extra syntax above a b c 10 20 30. By contrast, (setf a 10 b 20 c 30) has only three: two parens and setf. Let's count the crumbs:

  [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)
Re:Playing with Syntax by smallnamespace on Saturday August 20, 2016 @01:14PM (#12327427)
Token-counting is a strawman here; you can use more tokens and still have something that's easier for a person to read.

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.

Re:Playing with Syntax by kazinator on Saturday August 20, 2016 @06:48PM (#12328599)
Yes, you're eliminating complexity. Because there is a fixed amount of complexity in the semantics of the assignment operation itself. Having to parse some syntax with precedence and whatnot is extra complexity that doesn't further the goal of assigning to those three variables.

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.

Re:Playing with Syntax by smallnamespace on Saturday August 20, 2016 @07:41PM (#12328801)
> The ideal syntax for performing some operation O on entities X, Y and Z consists only of the symbols O, X, Y an Z

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?

Re:Playing with Syntax by int_19h on Saturday August 20, 2016 @08:54PM (#12328979)
All the extra punctuation in syntax is redundant in the same way serifs are redundant on letters - sure, you don't need them to be able to figure out what the letters are, but having them there makes it easier and increases your reading speed, despite the increased complexity of shapes.
Re:Playing with Syntax by kazinator on Saturday August 20, 2016 @10:57PM (#12329200)
When was the last time you saw a freeway sign in Times Roman or Garamond or their ilk? Or any other public signage related to transportation.

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.

Re:Playing with Syntax by int_19h on Sunday August 21, 2016 @01:50AM (#12329598)
When was the last time you've read a book typeset in a sans serif font?

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.

Re:Playing with Syntax by abritinthebay on Sunday August 21, 2016 @12:58PM (#12331608)
> When was the last time you saw a freeway sign in Times Roman or Garamond or their ilk? Or any other public signage related to transportation.

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

Re:Playing with Syntax by abritinthebay on Sunday August 21, 2016 @12:55PM (#12331592)
That's a lot of work to demonstrate that Lisp's syntax is less elegant than freaking ES6.

> 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.

Re:Playing with Syntax by kazinator on Sunday August 21, 2016 @02:51PM (#12332170)
I feel that I hadn't seen true beauty in a text editor window until I got involved with Lisp, and that EczemaScript is designed by imbeciles.

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.

Re:Playing with Syntax by abritinthebay on Sunday August 21, 2016 @04:59PM (#12332723)
> Basically, it boils down to token counts and the presence of implicit associativity and precedence rules.

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.

Re:Playing with Syntax by kazinator on Monday August 22, 2016 @01:43AM (#12334342)
I see; so when you say things like 'Lisp is many things, syntactically elegant isn't one of them' you are taken seriously, whereas if I say the opposite I am not; and it's because I have tried to reflect over my biases, and quantify them in some sort of objectively evaluable terms.
Re:Playing with Syntax by abritinthebay on Wednesday August 24, 2016 @02:00PM (#12353939)
No, it's when you define "beautiful" as "equivalent to lisp syntax" that you are not taken seriously.

Which you did. So you weren't.

Re:Playing with Syntax by lispm on Saturday August 20, 2016 @12:47PM (#12327292)
In CL without the need for destructuring:

    (setf (values a b c)
          (values 10 20 30))
Re:Playing with Syntax by icebraining on Saturday August 20, 2016 @12:49PM (#12327305)
That's still three superfluous words. I have to agree with abritinthebay, especially when comparing with Python's destructuring, which doesn't even need brackets:

  a, b, c = 10, 20, 30
Re:Playing with Syntax by lispm on Saturday August 20, 2016 @12:52PM (#12327317)
What about all those superfluous commas? I also dislike languages where expressions don't have visible bounds.
Re:Playing with Syntax by icebraining on Saturday August 20, 2016 @01:05PM (#12327381)
A line break isn't visible? Not by itself, I suppose, but in the code, it's hard to miss.
Re:Playing with Syntax by lispm on Saturday August 20, 2016 @02:10PM (#12327676)
for what expression does the line break stand, exactly?
Re:Playing with Syntax by smallnamespace on Saturday August 20, 2016 @02:22PM (#12327728)
But why must everything be an expression?
Re:Playing with Syntax by davexunit on Saturday August 20, 2016 @04:34PM (#12328201)
Because anything else is a language design mistake.
Re:Playing with Syntax by smallnamespace on Saturday August 20, 2016 @04:53PM (#12328271)
Can you justify that statement empirically?
Re:Playing with Syntax by 918723192 on Saturday August 20, 2016 @03:15PM (#12327937)
a, b, c is a tuple. Parentheses can be omitted, same as in some ML dialects:

  # 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)
Re:Playing with Syntax by kazinator on Saturday August 20, 2016 @12:58PM (#12327352)
Python needs a piece of whitespace on the left of the correct size and tab/space constituency, and a newline on the right.

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.

Re:Playing with Syntax by icebraining on Saturday August 20, 2016 @01:10PM (#12327407)
No, just the name and argument order of a bunch of functions/macros (set, setf, setq...).
Re:Playing with Syntax by smallnamespace on Saturday August 20, 2016 @03:01PM (#12327889)
> 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.

Re:Playing with Syntax by kazinator on Saturday August 20, 2016 @06:43PM (#12328586)
> By that logic, we ought to have parentheses around every mathematical expression as well.

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.

Re:Playing with Syntax by Macha on Saturday August 20, 2016 @03:39PM (#12328019)
> Python needs a piece of whitespace on the left of the correct size and tab/space constituency, and a newline on the right.

Good luck getting your lisp code merged with mismatched tabs/spaces or everything aligned to column 0.

Re:Playing with Syntax by abritinthebay on Sunday August 21, 2016 @01:08PM (#12331658)
Better, I wouldn't call it elegant though. But better than other Lisp example in this thread.

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.

Re:Playing with Syntax by Myk267 on Saturday August 20, 2016 @02:45PM (#12327825)
Or maybe it will invite them to try it out themselves?

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.