6 ms·
That explains why Lisp is so convenient for implementing DSLs. Homoiconicity skips all the bike shedding around syntax and parsing.
by giovannibonetti 3y ago
That explains why Lisp is so convenient for implementing DSLs. Homoiconicity skips all the bike shedding around syntax and parsing.
- nielsbot 3y agoLisp: "We got around parsing by getting rid of the syntax!" :)
- eru 3y agoLisp has syntax. It's just usually fairly straightforward (for the most parts). Forth also has an interesting simple syntax.
- deredede 3y ago"Lisp has no syntax" really means "Lisp has no specific syntax". Any well-parenthesized S-expr is a syntactically valid Lisp program, even if it is nonsensical. Most other languages (including Forth) have keyword and syntax-dependent structuring.
- eru 3y ago> Any well-parenthesized S-expr is a syntactically valid Lisp program, even if it is nonsensical. Which version of Lisp are you talking about? A very brief web search showed eg https://stackoverflow.com/questions/40210896/syntax-error-in-dr-racket https://stackoverflow.com/questions/40210896/syntax-error-in... For something really simple, try `(define define)` in Scheme. I'd say Forth has less syntax than Lisp. But that's perhaps a reflection of most Forth implementations using some clever tricks to offload much of what's handled by syntax in other languages. Eg defining new functions (ie 'words' in Forth terms) is not done via a special syntactic construct in Forth, but via 'immediate words'. The lines are a but blurry, though.
- deredede 3y agoThis is not a Lisp syntax error, this is a 'cond' macro syntax error. The language has no syntax, the constructs within the language can and do impose additional restrictions (not extensions - restrictions) when evaluated. You may not find the distinction useful, but it is there.
- eru 3y agoRacket calls it a syntax error. I defer to them on the classification of their errors.
- Zambyte 3y agoNeither Racket, nor any Scheme implementation calls (define define) a syntax error in general. It is only an error when define is defined to define, as it is in the base environment. If you have an environment where define does not define, (define define) may work. Welcome to Racket v8.9 [bc]. > (define (define x) (display "Look ma, no error!\n")) > (define define) Look ma, no error!
- lispm 3y agoIn Common Lisp the identifiers in package Common Lisp are not allowed to be redefined.
- Zambyte 3y agoIt may be semantically invalid in Common Lisp, but it is syntactically valid in Lisp (as seen by observing different dialects).
- lispm 3y agoThe term "Lisp" is undefined. Common Lisp is an actual standard for a programming language with a specification. Its core symbols are reserved identifiers. Anyway, if you would be allowed to reimplement a built-in operator, then from then on you would be using the new operator and you would be limited to its syntax. Common Lisp OTOH provides namespaces (called "package") and there is a pre-defined namespace "COMMON-LISP" for the core language.
- lispm 3y ago> Any well-parenthesized S-expr is a syntactically valid Lisp program It isn't. It's just a valid S-expr. For example ((a b c) (d e f)) is not a valid Common Lisp program. (let foo bar baz) is also not a valid Common Lisp program. The syntax for LET is: let ({var | (var [init-form])}*) declaration* form* SBCL: ; in: LET A ; (LET A ; B ; C) ; ; caught ERROR: ; Malformed LET bindings: A. ; ; compilation unit finished ; caught 1 ERROR condition LET is a built-in operator. It's not a function and not a macro.
- nielsbot 3y agoI forgot about Forth. Surely the king of non-syntax.
- eru 3y agoI used to like Lisp's homoiconicity. These days, I'm not even sure the concept makes any sense? What is it even supposed to mean? Lisp has (simple) syntax for creating literals and writing code. But when you inspect your data from the inside of Lisp, they don't have any more (or less) relation to that syntax than eg Python does. Eg no modern Lisp stores a function as an S-Expr of its syntax. You get an opaque piece of data that you can do certain operations on, just like in eg Python or Haskell. Lisp using S-Expressions is an interesting syntax choice, but that's it. It doesn't by itself have any deeper impact on the language. (Of course, socially it does have a deeper impact, because it makes it simple for language users to write macros that look exactly like built-in parts of the language, instead of bolted on. But that's all in human brains and social interactions, nothing fancy going on here on a technical level. If you wouldn't mind much more tediousness, you could implement seamless macros in almost any language as a pre-processing step.)
- thom 3y agoWell sure, if you hand wave away the main benefit of sexps then there aren’t many benefits.
- eru 3y agoOh, S-Expressions are great for certain kinds of things. I'm just having a problem with the concept of homoiconicity being touted as both coherent, and something that goes deeper than the very surface syntax level.
- bandrami 3y agoSimilarly Forth doesn't have a parser (though some implementations call their scanner a parser) and is great for writing DSLs