News for hackers. Stuff that matters.
Re:Lisp: It's Not About Macros, It's About Read by nessus42 on Saturday February 18, 2012 @03:06PM (#3607595)
One one side you have people like the author who crave the power of code-as-data more than they care about nice syntax and therefore love Lisp.

I crave both the power of code-as-data and nice syntax, which is why I love Lisp.

Re:Lisp: It's Not About Macros, It's About Read by haberman on Saturday February 18, 2012 @04:28PM (#3607803)
Some people like putting salt on grapefruit. I'm not saying that it's impossible to like Lisp's syntax, but empirically most people prefer the ALGOL-like syntax, which is why I referred to it in the next sentence as "conventional syntax."

I could attempt to prove to you that "conventional syntax" is inherently superior to Lisp syntax, but that would be a waste of both of our time.

Re:Lisp: It's Not About Macros, It's About Read by nessus42 on Sunday February 19, 2012 @03:26AM (#3608947)
Some people like putting salt on grapefruit.

You sound as if you think that putting salt on grapefruit is inherently strange, while in actuality there's a very good reason to do so: it reduces the perception of bitterness.

I'm not saying that it's impossible to like Lisp's syntax, but empirically most people prefer the ALGOL-like syntax

Empirically, most people prefer what they are already familiar with, so I'm not sure what this is supposed to prove, other than most people are already more familiar with Algol-like syntax.

For me, Lisp syntax has the definitive advantage that the first identifier in every expression tells me what to expect. I.e., I don't have to scan to the right to figure out what kind of expression this is. For me, this makes code much more readable. And this makes Lisp syntax more "nice".

Re:Lisp: It's Not About Macros, It's About Read by burgerbrain on Sunday February 19, 2012 @04:52PM (#3610549)
Presumably salt on grapefruit is thought to be weird since grapefruit is thought to be good for your heart, while the perception of salt is quite the opposite.
Re:Lisp: It's Not About Macros, It's About Read by krunaldo on Saturday February 18, 2012 @07:33PM (#3608203)
(+ 1 2 3) =

add 1 and 2 and 3

The syntax is a bit terse but if you teach people a good way to read it it becomes much more readable than 1+2+3

The only reason we prefer that way is that we are thought that syntax when we do math in school, I have found it much easier to teach people lisp who have no or very little formal education in math.

Re:Lisp: It's Not About Macros, It's About Read by Confusion on Sunday February 19, 2012 @03:53AM (#3608989)
This argument is based on too shallow an analysis and doesn't stand up to closer examination.

  (/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a))
Yeah, so it divides (the addition of (-b and the (sqrt of (the difference between (the product of b and b) and (the product of 4, a and c))) by (the multiplication of 2 and a))

Right, that's much easier than

  (-b + sqrt(b*b - 4*a*c)) / (2*a)
(-b plus the sqrt of ((b times b) - (4 times a times c))) divided by (2 times a)
Re:Lisp: It's Not About Macros, It's About Read by JBiserkov on Sunday February 19, 2012 @05:16AM (#3609088)
New lines in the Lisp, PLEASE :)

I see you omitted some parenthesis in the "conventional" expression, relying on the fact that multiplication takes priority over substraction. Making this fact explicit is exactly what makes Lisp better, especially for more complex domains: delegating priorities to the notation, freeing brain capacity for the actual problem.

Re:Lisp: It's Not About Macros, It's About Read by lispm on Sunday February 19, 2012 @05:25AM (#3609096)
If math is a problem for the user, there is the option to use a modified parser. For example using an infix parser called by a readmacro:

    (defun foo (a b c)
      #I( 

          (-b + sqrt(b*b - 4*a*c)) / (2*a)

        ))

    CL-USER 8 > (foo 1 2 3)
    #C(-1.0 1.4142135)
Re:Lisp: It's Not About Macros, It's About Read by Confusion on Sunday February 19, 2012 @05:33AM (#3609099)
Sure, there are solutions and it's awesome that they're both possible and easy to use. I'm not arguing against Lisp; I just don't agree that its syntax is better. I agree it is not worse, if you survey a sufficiently large variety of cases.

It may be bikeshedding, but I would not let 'blue is better than red, because the sky is blue' pass either.

Re:Lisp: It's Not About Macros, It's About Read by wicket232 on Monday February 20, 2012 @01:35PM (#3613324)
Once you add indentation, and know the simple rule that args line up vertically (unless they're so short that you'd rather leave them), the following is pretty easy to read:

    (/ (+ (- b)
          (sqrt (- (* b b)
                   (* 4 a c))))
       (* 2 a))
It tells me:

* there's a quotient of 2 things

* the first thing is a sum of -b and a sqrt

* the second thing is a product

and so on. Pretty nice. Of course, mathematical notation is more terse.

Re:Lisp: It's Not About Macros, It's About Read by Volpe on Sunday February 19, 2012 @12:11AM (#3608706)
Weak arguement. So rather than form a language around our existing learnings (in Math as you say). We should change all our existing learnings to suit a particular language... then it's more readable... riiiiight, good luck with that. :)
Re:Lisp: It's Not About Macros, It's About Read by dman on Saturday February 18, 2012 @05:00PM (#3607863)
Syntax is the vietnam of programming languages.
Re:Lisp: It's Not About Macros, It's About Read by anamax on Saturday February 18, 2012 @05:36PM (#3607946)
> I could attempt to prove to you that "conventional syntax" is inherently superior to Lisp syntax, but that would be a waste of both of our time.

Yes, trying to prove falsehoods is a waste of time.

Conventional syntax is neither conventional nor suited to humans. (If it's "conventional", why isn't there more agreement as to what it is? If it's suited to humans, why aren't there more than 100 who actually know it for any given language?)

Re:Lisp: It's Not About Macros, It's About Read by wvenable on Saturday February 18, 2012 @04:30PM (#3607805)
Lisp is effectively the parse tree in other languages. In the gap between human and machine, Lisp is closer to the machine. Some people like that, but the majority prefer a language that is closer to the human (and perhaps the closer you get to the human the less nice it gets depending on how you define "nice").
Re:Lisp: It's Not About Macros, It's About Read by anamax on Saturday February 18, 2012 @05:39PM (#3607950)
> the majority prefer a language that is closer to the human

Closer to "the human"? Do you know more than 3 people who know C++ operator precedence?

Humans don't handle operator precedence very well.

Re:Lisp: It's Not About Macros, It's About Read by haberman on Saturday February 18, 2012 @07:48PM (#3608235)
Why then has math (which is read and written only by humans) used infix notation for hundreds of years, whereas prefix/postfix notation were only developed in the 20th century and today are used only by Computer Scientists?

You don't have to know an entire operator precedence table to read and write idiomatic infix-notation code. Precedence is defined such that common expressions evaluate as people intuitively expect (a notable counterexample is "x & y == z" in C). Parentheses are always available to clarify more complicated expressions.

Re:Lisp: It's Not About Macros, It's About Read by brlewis on Saturday February 18, 2012 @08:27PM (#3608314)
Humans who do a lot of math switch notations when convenient. For example, for addition we'll sometimes put a summation sign in prefix notation. For division we like to put the numerator above the denominator, a notation that's inconvenient in a programming language.

Come to think of it, humans usually add and subtract by stacking numbers vertically. I don't think you can point at infix notation as "the" human-friendly notation.

Re:Lisp: It's Not About Macros, It's About Read by Volpe on Sunday February 19, 2012 @12:15AM (#3608713)
Have you seriously seen (non-computer) people write simple arithmetic as + 1 3 ?

This feels like a discussion based in fiction...

Re:Lisp: It's Not About Macros, It's About Read by lispm on Sunday February 19, 2012 @12:34AM (#3608742)
I've seen lots of people doing 1 enter 2 + on their HP calculators. Using them with RPL, reverse polish lisp.
Re:Lisp: It's Not About Macros, It's About Read by burgerbrain on Sunday February 19, 2012 @04:21PM (#3610453)
Postfix notation is popular in the financial industries.
Re:Lisp: It's Not About Macros, It's About Read by burgerbrain on Saturday February 18, 2012 @10:41PM (#3608582)
One could have made the same argument in favour of Roman numerals, in the face of the less familiar Arabic numerals
Re:Lisp: It's Not About Macros, It's About Read by jhuni on Saturday February 18, 2012 @10:52PM (#3608604)
Math was written on paper long before there were computers. As a result, the use of infix notation was an act of necessity not a calculated decision. Now that we have computers and keyboards we should use prefix notation.
Re:Lisp: It's Not About Macros, It's About Read by CJefferson on Sunday February 19, 2012 @06:02AM (#3609124)
So you think we should teach in schools (from an example above):

(/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a)) ?

Re:Lisp: It's Not About Macros, It's About Read by burgerbrain on Sunday February 19, 2012 @04:48PM (#3610531)
Seems like a great idea to me.

I take it you think there is something intrinsically wrong with that idea?

Re:Lisp: It's Not About Macros, It's About Read by CJefferson on Monday February 20, 2012 @11:59AM (#3612949)
Certainly, I would hope it would have been obvious, but we might each have different opinions of obvious!

I find it very hard, without bracket counting, to see exactly what the '+' and '/' bind to. With the more traditional:

(-b + sqrt(bb-4ac)) / (2a)

I find in only a glance I can tell what everything is binding to.

Re:Lisp: It's Not About Macros, It's About Read by anamax on Monday February 20, 2012 @05:41PM (#3614274)
> I find in only a glance I can tell what everything is binding to.

It must be nice to live in a world with only 4 infix operators and expressions that have only 3 infix operators.

For example, lots of folks think that sqrt should be a prefix operator, not yet another function. I suppose you're going to assume that the top bar will serve as parentheses.

BTW "-b + sqrt(bb-4ac) / 2a" is the interesting expression. Is it "(-b + sqrt(bb-4ac)) / (2a)" or "-b + (sqrt(bb-4ac)) / 2a)" And, are you certain what "bb-4ac" means? (There's at least one major language where it doesn't mean "(bb)-(4ac)".)

Re:Lisp: It's Not About Macros, It's About Read by CJefferson on Thursday February 23, 2012 @05:29AM (#3624462)
We aren't talking about programming languages. We are talking about teaching math in school. In most of school mathematics, there are only 4 infix operators (well, and also the comparison operators).
Re:Lisp: It's Not About Macros, It's About Read by anamax on Thursday February 23, 2012 @09:46AM (#3625074)
> We are talking about teaching math in school. In most of school mathematics, there are only 4 infix operators (well, and also the comparison operators).

And that's how the exceptions swallow the rule. And, it's also how we get infix programming languages where that's definitely not true, and so on. Where should we make the switch?

Also, only four? What about set operations?

Re:Lisp: It's Not About Macros, It's About Read by jhuni on Monday February 20, 2012 @05:49PM (#3614305)
I would teach it like this:

  (/ (- (sqrt (discriminant a b c)) b)
     (* 2 a))
Re:Lisp: It's Not About Macros, It's About Read by andreasvc on Sunday February 19, 2012 @06:22AM (#3609133)
Why exactly is it a necessity to use infix on paper? And what exactly is the argument for using prefix just because we have computers? I'd argue quite the opposite, computers give use even more convenience to use whatever we like. I think it is a rather arbitrary choice, but it may relate to the prevalence of subject-verb-object in (spoken) languages; i.e., operators act like a verbs.
Re:Lisp: It's Not About Macros, It's About Read by lispm on Sunday February 19, 2012 @12:36AM (#3608745)
if you look at math on paper, that's definitely not 'infix'.
Re:Lisp: It's Not About Macros, It's About Read by 6ren on Sunday February 19, 2012 @03:17AM (#3608934)
It's even stronger, in that mathematics generalized arithmetic algebra into groups, fields, rings and other things I don't understand. Examples of specific algebras include: boolean, relational and Kleene (aka regular expressions).

Other notations are used, but with a frequency similar to pre-fix (lisp) and post-fix (forth). "Associativity" (not affected by order of evaluation) only makes sense for in-fix.

But it really could just be familiarity, I guess. I can't see how to determine it either way. But regardless of the cause, there's overwhelming evidence that people, in fact, prefer in-fix.

Re:Lisp: It's Not About Macros, It's About Read by anamax on Tuesday February 21, 2012 @12:06PM (#3617164)
> But regardless of the cause, there's overwhelming evidence that people, in fact, prefer in-fix.

How many people have seen anything other than in-fix? Of those, how many got a fair shot at an alternative?

Re:Lisp: It's Not About Macros, It's About Read by anamax on Monday February 20, 2012 @05:24PM (#3614222)
> You don't have to know an entire operator precedence table to read and write idiomatic infix-notation code.

If it's "idiomatic", why is there such disagreement?

> Why then has math (which is read and written only by humans)

Convention has a lot of value. That said, mathematicians don't have to worry about getting things wrong. It's just paper, and they're happy to let humans fix up the errors.

> Parentheses are always available to clarify more complicated expressions.

Unnecessary parentheses are how humans deal with the fact that they can't handle infix.

Re:Lisp: It's Not About Macros, It's About Read by agumonkey on Saturday February 18, 2012 @08:23PM (#3608302)
Closer to a virtual machine which treats most things as function, nouns, and lists; fairly close to human thoughts. Naked and abstract and systematic hence easier to process, but beside cad/cdr name, I don't see too much machinery here.

here's IPL, an influence of lisp, also a list processing language (c/p from wikipedia)

  IPL-V List Structure Example
  Name	SYMB	LINK
  L1	9-1	100
  100	S4	101
  101	S5	0
  9-1	0	200
  200	A1	201
  201	V1	202
  202	A2	203
  203	V2	0
How human LISP feels now ;) ?
Re:Lisp: It's Not About Macros, It's About Read by calibraxis on Saturday February 18, 2012 @04:08PM (#3607759)
Yes, I don't see how mainstream languages can possibly be considered aesthetically pleasant, with the possible exception of Python. I wouldn't visit a gallery that shows them off.

I find Lisp (particularly Clojure) much more aesthetically pleasant, in that it communicates better with me. With Paredit, it's even better to the touch.

(If there one day came to exist something even better on these metrics, then I'm sure I would start to prefer it aesthetically.)

Re:Lisp: It's Not About Macros, It's About Read by kls on Saturday February 18, 2012 @05:13PM (#3607890)
I agree I don't get the syntax argument. I am sure that as one of the other posters mentioned that one is more favored than the other, but once you know the limited syntax of a Lisp it becomes fairly readable. For me it's all about figuring out scope, once I know what denoted scope, it is fairly easy to format the code into a readable format for my mind. The thing about the Lisp dialects is the rules for syntax are so simple that once understood they become perfectly readable, at least to me they do.
Re:Lisp: It's Not About Macros, It's About Read by edoloughlin on Sunday February 19, 2012 @03:45AM (#3608972)
> I agree I don't get the syntax argument

Doubly agreed! I learned Clojure just over a year ago and will never look back. My attitude to people complaining about parents is that that should just get over it. That one hang up is actually holding them back.

Re:Lisp: It's Not About Macros, It's About Read by edoloughlin on Sunday February 19, 2012 @04:29PM (#3610470)
That should have been 'parens', not 'parents', of course. Although, in another context, it's completely valid!
Re:Lisp: It's Not About Macros, It's About Read by ebiester on Saturday February 18, 2012 @11:59PM (#3608690)
I'll explain it to you: Where is the bug in..

(defun substitute-in-replacement ($-value replacement) (cond ((null $-value) replacement) ((null replacement) ()) ((eq (car replacement) '$) (cons $-value (cdr replacement))) (T (cons (car replacement)) (substitute-in-replacement $-value (cdr replacement)))))

From: http://www.csc.villanova.edu/~dmatusze/resources/lisp/lisp-e... with one paren moved.

I remember, when I was taking a class on AI, looking for some sort of style guideline that would help me get through the learning curve, but the FAQ (I want to say it was comp.lang.lisp) just had "coming soon." So this would be the allegro editor in 2001 or 2002. It may be obvious to an experienced hand, and perhaps if there was some sort of best practices when I was learning it I wouldn't have had the same problem, but I just remember the frustration of my mind playing tricks on me and (even with syntax highlighting) trying to match parens that I thought were there.

Re:Lisp: It's Not About Macros, It's About Read by twstws on Sunday February 19, 2012 @12:44AM (#3608755)
1 paren moved and all line breaks and indentation removed. This is intentionally obfuscated. Is there any language that is easy to read when you put five lines of code together like This?

I haven't read a lisp style guide, Emacs just takes care of indentation - it is immediately clear when a paren is wrong because the shape of the function is wrong. If you are writing lisp with an editor that doesn't do this, get a better editor, don't blame the language.

Re:Lisp: It's Not About Macros, It's About Read by ebiester on Sunday February 19, 2012 @02:57PM (#3610193)
Oy. The mistake was actually in posting too late and not using the proper code tag. Don't drink and post, kids. ;) When I brought the code into vim I used the same indentation as the example, I saw that the indentation changed, but you're saying "The shape of the function is wrong."

It's quite possible my experience as a programmer today would be different than when I started -- I mean, I made it through a few chapters of SICP without such troubles, but in the back of my head was the memory of trying to figure out my logic error in a bit of code when it was really a misplaced paren.

Re:Lisp: It's Not About Macros, It's About Read by berntb on Sunday February 19, 2012 @05:20AM (#3609090)
>>Is there any language that is easy to read when you put five lines of code together like This?

Arguably Python -- but to get that, Python sacrificed the possibility of both usable anonymous functions and the possibility to cut-paste a code fragment and just ask the editor to reindent.

Hardly worth the price.

Re:Lisp: It's Not About Macros, It's About Read by lispm on Sunday February 19, 2012 @04:56AM (#3609068)
The Lisp compiler tells you:

    (defun substitute-in-replacement ($-value replacement)
      (cond ((null $-value) replacement)
            ((null replacement) ())
            ((eq (car replacement) '$)
             (cons $-value (cdr replacement)))
            (T (cons (car replacement))
               (substitute-in-replacement $-value (cdr replacement)))))

    CL-USER 5 > (compile 'substitute-in-replacement)
    ;;;*** Warning in SUBSTITUTE-IN-REPLACEMENT: CONS is called with the wrong
    ;;;     number of arguments: Got 1 wanted 2
    SUBSTITUTE-IN-REPLACEMENT
Lisp compilers able to present these error messages are in use since more than 40 years. Common Lisp has them since day one.
Re:Lisp: It's Not About Macros, It's About Read by lisper on Sunday February 19, 2012 @03:41AM (#3608964)
Took me less than a minute to find it. Just pasted the code into my Lisp editor (I use CCL), added a few line breaks in the obvious places, hit TAB a few times, and it was immediately obvious.

Actually, it's pretty obvious even without doing all that. CONS always takes two arguments.

Re:Lisp: It's Not About Macros, It's About Read by calibraxis on Sunday February 19, 2012 @07:50AM (#3609232)
My code doesn't look like that. For 30-50% of my code, I try to use a style more like:

  (defn thingies [id]
    (->> id
         fetch
         read-json
         :rows
         (map :thingy)))
(Of course, my code is often more complex and messier than that, even when using ->>, but some fairly significant percentage of my code does look that simple.)

I'm sure there's stuff to criticize about Clojure, but we can look at real-world code in another mainstream language (Javascript+node.js? PHP? Java?) and point out readability problems too. (Python maybe being an exception in terms of readability-in-the-small, for things that fit in the mainstream style. Though as someone pointed out, there's maybe some problems with manipulability.)