5 ms·
Homoiconicity isn’t the point (2012)
- taeric 6y agoThis was what turned out to be more of a subtle point than I thought it would be in https://taeric.github.io/CodeAsData.html https://taeric.github.io/CodeAsData.html For me, there is a mindset of how to read the code that is unlocked by not having to specially parse so much of it in my head. It really can be seen as a list of code. And I can more easily see ways of transforming the code. Granted... I actually like the LOOP and FORMAT forms a lot. They somewhat break the easy to parse, but often they work as a coherent unit of code by themselves.
- k__ 6y ago"What makes Lisp’s syntax powerful is not the fact that it can be represented as a data structure, it’s that it’s possible to read it without </em>parsing</em>." For me that always was exactly was homoiconicity was all about.
- rscho 6y agoHomoiconicity is a start. But the killer feature is simplicity. In Lisp, only symbols and parentheses. In prolog, only predicate head, body and atoms. This is what makes those two languages so suitable to syntactic macros, while other languages claiming homoiconicity with more syntactic irregularity make syntactic macros impractical (although certainly possible). IMO, semantic AST-level macros are certainly a better choice in non homoiconic and syntactically irregular languages.
- chriswarbo 6y agoEven without macros, it's useful for languages to have a format that's "readable without parsing", since new language versions can introduce keywords that break existing tooling. The worst case I experienced was a project to perform static analysis on Haskell code. Some optional features (e.g. LambdaCase) alter the way files must be parsed, and I recall at least one causing an ambiguity. This made parser libraries pretty useless, so I had to use the GHC compiler directly. This was around 2015, when GHC's API was much harder to use programatically; in particular it would often crash (saying "the impossible happened") if it wasn't given exactly the right "DynFlags". Those were hard to guess, so had to be passed through as commandline arguments, essentially re-creating the GHC command! Sometimes those features and flags are toggled in a "pragma" comment at the top of a file, but it is also very common for projects to specify these in a separate config file for the Cabal build system. Those files are a non-standard format, so we have to parse them using the Cabal library. Hence I ended up essentially re-implementing the Cabal command, as a way to pass the right arguments to my re-implemented GHC command. That still struggled to parse Haskell code, due to widespread use of the C preprocessor (CPP). I ended up using the vanilla GHC and Cabal commands, but added my own optimisation pass as a GHC plugin. This pass is a function accepting and returning "GHC Core" (one of GHC's intermediate representations); the only side-effects it permits are for error reporting. Hence my pass just returned its input unmodified, whilst also printing it to stderr (as s-expressions, for simplicity). This "GHC Core" representation was usable for my project, but I still find it incredible that I wasn't able to reliably parse Haskell code (especially given how well-suited Haskell is for parsing!).
- Syzygies 6y agoProcessing parentheses is still parsing. It's kindergarten-level parsing, but it's still parsing. I've written thousands of lines of scheme code preprocessed to eliminate most parenthesis. I'm convinced Lisp self-asphyxiated by fighting a last stand on parentheses, which is so far from the point of Lisp. With modern editor "language server" support and syntax coloring, languages can shape-shift to any appearance they want, separate from meaning. While I love the poetic look of parenthesis-spare Lisp, Bill Joy got it right when he said that code density on a screen affects programmer productivity. I love Haskell, both for this and because one reasons about the activity of programming as if one is doing algebra. While Lisp more easily modifies itself than any other language, macros are bolted on. No one can tell me with a straight face that with a thousand runs of the civilization simulation, our Lisp macros would be the best run. I'd love to see a language where manipulating the language is the core strength, and all ease with data structures follows as a consequence. Lisp is not that language; peek into some of the other simulation runs.
- lmilcin 6y ago> I'm convinced Lisp self-asphyxiated by fighting a last stand on parentheses, which is so far from the point of Lisp. I think the reason Lisp self-asphyxiated is because people don't get it. Most try to spend a little bit time programming it as if it was C/Java/Python/whetever else they have used on their last project. They just see a language that can do what they need but it is all wonky and so why bother? Compared to other languages, to get benefits from using Lisp you actually need to understand what the benefits are and what causes the benefits. You can switch from C to Python and reap benefits of Python without having some kind of deep understanding. That's because programming in Python is basically same thing as programming in C, it is just more efficient. There is less stuff to set up (unless you run into compatibility problems), less stuff take care for (begone pesky pointers and memory allocation!) and better API to do repeatable tasks. On the other hand programming in Lisp is different than every other language. But you also can program as if you were programming any other language. So you get confused about what makes Lisp different and if you don't stick it out you might think you just learned Lisp and "what is all teh fuss about?" I think getting from regular programming to Lisp should be presented as same step change as going from not programming to programming. Person who has never programmed and never heard about programming might have a lot of trouble understanding why you would even want to program (in the end it is just adding numbers -- why would that accomplish anything, I am not an accountant?)
- airstrike 6y agoThat example at the very end seems very contrived... It's not really valid JS, as far as my noob eyes can tell
- draw_down 6y agoIf the value of Lisp is how wonderfully readable it is... then I guess it was never meant to be with me and Lisp.
- skybrian 6y agoWhat you get from the flexibility of having macros, it seems like you lose by being unable to do static analysis at any level other parentheses matching? In particular, consider trying to figure out all usages of a function without executing code. I don't think you can even resolve imports without possibly getting fooled by macros that you didn't hard-code an understanding of? (But on the other hand, it's not going to be 100% in languages that support reflection either. We just assume that's rare.)
- Firadeoclus 6y agoIf you have access to the whole codebase, and the ability to ask the system for code after macro expansion, you can do any kind of analysis you want.
- skybrian 6y agoOne problem is that macro expansion is arbitrary code execution, which means your static analysis is potentially insecure. But I suppose it could run in a sandbox. A second issue is that the macro-expanded code is a lowered representation compared to to what the user sees. This tends to make user-friendly error reporting harder. Another problem might arise when macro expansion is intermixed with normal execution, making it harder to just expand macros with executing code. Then you can still do a lot in a debugger, but that's quite different than static code analysis.
- didibus 6y agoThe reason you don't need to parse text is very much because of homoiconicity. Homoiconicity = same representation It means that the way you represent code in a language is the same way you represent some data-structure in that language. This applies both syntactically and semantically. (+ 1 2) This is the Lisp syntax for a list of three elements. Parenthesis denote a list, and each word inside it denote an element of that list. The above list has elements +, 1 and 2. So the above code is the syntax for a list, and when you deserialize this (read in Lisp parlens), you get a list of three elements. This is the semantic part. Now you have a List object of three elements. You can now loop over this list, access elements in it, change the order of the elements, you can append or prepend more elements to it, remove elements, and whatever else you can do with a list data-structure. Finally, it happens that code is represented this way as well. So syntactically if you want to add 1 and 2 together, you'd also write: (+ 1 2) And semantically, the interpreter/compiler will not take text as input, it will take a list of three elements as input, because code is assumed to be modeled as a list of elements. Not using some special CompilerList, but using the standard list data-structure you use for any other list. Which means to execute code, you take text which models code using the syntax used to represent lists, and you parse/deserialize it (read it) into a list data-structure, and then you feed this list to the evaluator which will execute it as code. Thus the textual representation for code and for a list is the same, and the in-memory representation of code and of a list is the same, and finally this list can be executed as code or simply processed as a list. This is homoiconicity.
- cout 6y agoI would love to see a language with exactly what you described, but with dictionaries instead of lists as the fundamental data structure.
- didibus 6y agoYa that'd be interesting. How do you imagine the representation and evaluation semantics working? Something like: {call: function, arg1: value1, argN: valueN} Instead of (function value1 valueN) So maybe you'd have: { do1: { call: defn, name: hello, args: {first: String, last: String}, ret: IO, impl: { call: print, msg: { call: concat, strings: ["Hello ", first, " ", last] } } }, do2: { call: hello, first: "John", second: "Doe" } } Where the number after "do" is the order in which things should execute, or maybe we can simplify it by using insertion order preserving maps... Looking at it, if people thought nested parens made for an eyesore, I'm not sure this would be any better received haha.