3 ms·
> The left looks a lot like a typical AST for many languages.... Right, and this is what's meant by the oft-repeated statement "LISP has no syntax." Of course
by actually_a_dog 4y ago
> The left looks a lot like a typical AST for many languages....
Right, and this is what's meant by the oft-repeated statement "LISP has no syntax." Of course it has syntax in the sense that if you were to go in and delete one of those parens, the whole thing wouldn't compile, but the syntax it does have is 100% regular.
- Banana699 4y agoWho cares? Assembly is regular*, very much so. There is a single control flow construct, in conditional and unconditional flavors. There is a single language construct, of which the single control flow construct is but a special case. Code is Data and Data is Code. Everything is possible. You don't need regularity or simplicity, you need automation. Programming Languages are tools to under-specify a problem\process\pattern\solution\structure and still get an executable that does something useful, meaning the parts that weren't specified were filled in by the machine (in any way necessary), meaning automation. In other words, "A low level programming language is that which requires attention to the irrelevant", per Alan Perlis. In that light, lisp's syntax is awful, you're laying down the AST yourself instead of making a parser figuring it out from program text. You're paying precious attention to the extremely irrelevant, the fact that a function's body is nested under its name, the fact that a control construct wraps its code, instead of letting those trivial facts fade into the background of a nicely-designed grammar and actually focus on the code itself. There is literally 0 need for making code-as-text reflects code-as-tree, Mathematica represents every single language construct as a nested list underneath, and yet it has an extremely rich and pleasant syntax, full of sugar and shortcuts and alternate forms. It can do this because it understands a very fundamental point that lisp syntax fans too often miss : text is irrelevant. The string "(+ (* 4 10) 2)" is not an S expression, its the textual form of an S expression, the serialized form. You can't do anything useful with it without parsing, the actual S expression is a hierarchical object graph in memory, you can either get it from the text by quoting the text, or immediately evaluate it by entering the text directly into an interpreter (which gets the tree first). In all cases, there is no reason why quoting `while (cond) {exprs}` can't evaluate to the list (while cond (exprs)). You are already parsing the text anyway, quote is nothing but invoking the parser from within a program, so make the textual form convenient to humans while you're at it, a simplistic form benefits no one but the parser (a machine, the very thing that needs to work hard). Lisp's big idea is just making the compiler's services available through an easy API, this has absolutely nothing to do with its crippled syntax, it can be done by any language of any syntax whatsoever, much better than the 1960s hack lisp fans has stockholm-ed themselves into loving. To the extent it's rarely done in mainstream languages, it reflects the designers' choice. * : I'm assuming a remotely sane ISA, not the excrement known as x86.
- lispm 4y agoLisp has quite a bit more syntax, since it has a two stage syntax. The first stage is a syntax for data, called s-expressions. The parentheses are a part of that data syntax. Examples for s-expressions: 12 1/3 rome (rome is a city in italy) (rome (city . italy) (capital-of italy)) (rome local-name "Roma") and more. The s-expression syntax is extensible via reader macros. Lisp programs then are made out of s-expressions and there is a syntax for Lisp. Additionally the Lisp syntax is extensible via macros. Example: (let ((a 10) (b 10)) (declare (integer a b)) (+ a b)) Above is a LET expression for spanning a local lexical scope for variables. The syntax for LET would be (in some kind of EBNF notation): let ({var | (var [init-form])}*) declaration* form* With then more syntax for DECLARATION, FORM, ...