3 ms·
> S-expressions are definitely a syntax For data. s-expressions are not a syntax for Lisp. Only for data. > You still need a parser, because there's still qui
by lispm 13y ago
> S-expressions are definitely a syntax
For data. s-expressions are not a syntax for Lisp. Only for data.
> You still need a parser, because there's still quite a bit of ambiguity that gets introduced by language features like macros.
Macros introduce no ambiguity. They are destructuring and/or transforming the code.
Much less noise than your Ruby example:
(mapcar 'sqr (in-range 100))
(loop for n from 1 to 100 collect (sqr n))
Lisp as a programming language is based on words, tree structure and indentation, not so much on special characters. That's different from Ruby. But reading and parsing words is not really different to learn, otherwise you would have problems reading this text, which has lots of words and few special character.
- vinceguidry 13y ago> For data. s-expressions are not a syntax for Lisp. Only for data. Such a strange statement! Code IS data in Lisp. > Macros introduce no ambiguity. They are destructuring and/or transforming the code. And just what do you think syntax rules do? Any language could be represented with s-expressions. They just choose not to because s-expressions are a pain in the ass to read. The earlier example mapping square over a range expressed the exact same idea, so the representation is identical. You could write code to transform Ruby into s-expressions the same way Coffeescript compiles to Javascript. Nobody has yet, guess why? > Much less noise than your Ruby example: One could argue that the glut of parentheses are themselves noise. There are other ways of structuring Lisp programs that don't use them, but rather a one statement per line syntax like every other language. Also that prefix notation isn't natural for humans to read, dot notation is much more intuitive, which is why it's used in so many languages. Also that the special characters in, say, Ruby's block syntax reduce noise by providing visual cues to what parts of your code are what. But whatever, if you think (1..100).map {|x| x ** 2 } is noisy, then there's really no point in arguing with you, because we see the world two totally different ways. And this: (loop for n from 1 to 100 collect (sqr n)) ...looks exactly like a Ruby-style DSL implemented in Lisp. If I saw that in someone's code I'd be like, WTF is that doing? A method with 8 parameters? Oh wait, it's a macro. Why use a macro for that, what's wrong with building the range with a function instead of reimplementing BASIC in Lisp? Isn't the whole point to get away from imperative style?
- lispm 13y ago> Such a strange statement! Code IS data in Lisp. Code is represented as data. But that does not mean any data is code. For example (defun foo (a) (let ((b 10)) (+ a b))) is valid data and valid code. (defun (foo a) (let b 10 then (+ a b))) Above is valid data, but not valid code. CL-USER 27 > (defun (foo a) (let b 10 then (+ a b))) Error: (FOO A) is neither of type SYMBOL nor a list of the form (SETF SYMBOL). The syntax for DEFUN is: defun function-name lambda-list [[declaration* | documentation]] form* The syntax for LET is: let ({var | (var [init-form])}*) declaration* form* Both syntax definitions are violated. Obviously, the syntax of s-expressions is not enough to describe the syntax of Lisp. Far from it. S-Expressions just describe a textual syntax for data: symbols, numbers, strings, lists, cons cells, ... But it does not describe the syntax for defining functions, defining variables, exception handlers, function calls, etc. > They just choose not to because s-expressions are a pain in the ass to read. They aren't. > Isn't the whole point to get away from imperative style? Lisp makes no commitment to a particular style. 'imperative' is just fine. As is functional, object-oriented, rule-based, ...