3 ms·
IMO, the ease of manipulating Lisp code comes from that code being internally represented as a tree. But that doesn't mean that the syntactic representation has
by int_19h 9y ago
IMO, the ease of manipulating Lisp code comes from that code being internally represented as a tree. But that doesn't mean that the syntactic representation has to be so closely mapped to that underlying tree. Syntactic sugar is good! In fact, it's so good that even Lisp has some - you still write '(1 2), even though your macro will see (quote 1 2).
My point is, essentially, that raw S-exprs, or even S-exprs with the usual Lisp extensions, are too "bitter" - there's not enough syntactic sugar there to have them go down smoothly.
For a very extreme opposite example, consider R. Under the hood, any R program is represented as S-expr style tree (the corresponding data type is "call" - but it's basically just a linked list of arbitrary objects, including other call objects, and its interpretation is exactly like a Lisp S-expr - first item is what we're invoking, the rest are arguments).
Then on top of that they have created a C-style syntax. But that syntax is pure syntactic sugar - there's an exact one-way mapping from it to the actual call tree, and there's a canonical back-mapping as well. And you can skip the syntax and write everything in pure calls if you really wanted to.
Now, I'm not claiming that this is the sweet spot. But I'm pretty sure that S-exprs aren't it, either. It feels like there can be some middle ground, where the original tree structure is still fairly recognizable, but also with enough sugar that common patterns (e.g. variable bindings, function definitions, conditionals etc) are easy to parse visually.
- lispm 9y ago> '(1 2), even though your macro will see (quote 1 2). '(1 2) is (quote (1 2)), not (quote 1 2) > that common patterns (e.g. variable bindings, function definitions, conditionals etc) are easy to parse visually. Actually those Lisp patterns are not difficult to parse for humans. It's just that it looks a bit unfamiliar for non-Lisp users. The human visual system is capable to deal with that quite easily, it just might take learning. Humans can for example read book pages very fast even though there are very little visual clues in long sequences of text. It's just that humans have read a lot of those books... The visual pattern for variable binding in Lisp is: LET var value var value var value expression expression expression That pattern is easy to spot visually. In actual Lisp code it is: (let ((var value) (var value) (var value)) expression expression expression) The top-left item defines the structure of the rest. That item is easy to find. Here it is LET. All you need to know is what item has what pattern. There are a few basic patterns and combination of those. Once you learn about 10 - 20 of those patterns and understand that something like `WITH-FOO` will give you a clue what pattern to expect, then it is fairly easy to read Lisp. Typical patterns: function call sequence binding list with scope tree if function calls property list association list conditional expression and some more...
- int_19h 9y agoAt this point we're basically both making unsubstantiated assertions. Anecdotally, I know that I was able to learn to read C, Pascal, BASIC etc fast much easier than I was able to learn to read Scheme fast. I've asked this question to other people, and it seems to be a common thing. From this I conclude that visually parsing Lisp is more taxing. Yes, you may train yourself to do so fast - but you end up spending more time and effort on that. Again, this is anecdotal. A proper way to resolve this question would be to have a controlled study where a bunch of people not previously exposed to any language is given a crash course in, say, S-exprs and JSON, and then asked various data retrieval tasks on input of increasing complexity.
- lispm 9y agoMost people don't put much effort into it. Since you learned C, Pascal, Basic, ... you already had expectations how a program looks like, how it works and how to develop code. People also hear that Lisp is difficult to learn and exotic, this creates another negative bias. The next problem when learning Lisp is that the whole combination of syntax, semantics and pragmatics is new. Thus people might be able to read the code, but they have difficulties understanding the meaning, given that prior exposure to other programming language might not help here. They also may not be familiar with he particular interactive style of development and not see the advantages of working with code as data. The typical old saying is that everybody can learn the basics of Lisp in a day, unless one already knows FORTRAN, then it takes three day. The best way to get over these hurdles is to read and write a substantial amount of code. Luckily Lisp has some great books to learn from.
- kazinator 9y agoA page of C that conforms to common coding conventions does next to nothing. I can read it fast: "oh this is yet another reinvention of getting a line of arbitrary length from a FILE stream". Look; there is the realloc, the getc, the doubling in size of the buffer. There, I read it in 3 seconds! Three weeks later, I spot the failure to null-terminate the line in a corner case ...
- mschaef 9y ago> IMO, the ease of manipulating Lisp code comes from that code being internally represented as a tree. I don't think this is sufficient to explain the ease of manipulating Lisp code, After all, most languages are processed through an internal tree representation. (This fact is inherent to the grammars used to specify and parse those languages.) The only real exceptions I can come up with are concatenative languages like Forth, PostScript, and RPL and in these cases the syntax is truly primordial. (Which also carries its own advantages.) Where Lisp's s-expressions both shine and suffer is that they bring the structure of the initial syntax tree right up to the textual surface of the language. With some exceptions (like the quote syntax you mention), there are syntactic textual delimiters at either end of a Lisp ASP node, which is not even usually the case in an infix language. Just to illustrate, take these two (hopefully!) equivalent expressions... one in infix and the other in an s-expression. (> (+ x (* 2 z)) (- y 3 u)) x + 2 * z > y - 3 - u Given those two, and an editor command that selects a sub-expression or broadens a selection to include the enclosing sub-expression, where is it more obvious where the sub-expressions begin and end? The parenthesis in Lisp clearly delimit the nodes.... which makes it easier to identify the tree structure at a glance. Of course, it also makes it less-usual for human readers, who are well trained in infix. (Although I should point out that reading the infix requires being aware of hidden precedence and associtivity rules for the operators in use.... which is often managed by conventionally requiring extra parens, etc.) This is the trade-off I was referring to. From a couple posts down: > At this point we're basically both making unsubstantiated assertions. Anecdotally, I know that I was able to learn to read C, Pascal, BASIC etc... A proper way to resolve this question would be to have a controlled study where a bunch of people not previously exposed to any language is given a crash course in, say, S-exprs and JSON, and then asked various data retrieval tasks on input of increasing complexity. The way this is written almost implies that there is a single continuum on which these syntaxes can be ranked into better and worse. I really think this is something that's much more subject to opinion and personal point of view than that. As positive as you've been about infix syntax, I can state that, for me, the prefix syntax tends to feel more right. In other words, I don't think this is as much either/or as it is both approaches have strengths and weaknesses.
- kazinator 9y agoAnother thing is the ease and regularity of formatting into multiple lines: (> (+ x (* 2 z)) (- y 3 u)) (> (+ x (* 2 z)) (- y 3 u)) (> (+ x (* 2 z)) (- y 3 u)) Algol like languages are expected to use indentation for major structure, and expressions to be small, all in one line. Breaking infix into multiple lines is never satisfactory.