43 ms·
as i was talking to a friend about clojure i came up with an analogy i cant shake: clojure is what happens when you just make your programmer directly write an
by swyx 7y ago
as i was talking to a friend about clojure i came up with an analogy i cant shake: clojure is what happens when you just make your programmer directly write an AST. a bit reductionist, but anyone care to debate this?
- _hardwaregeek 7y agoIsn't that the point of lisp and homoiconicity in general? That you're writing an AST that you can also treat as a data structure?
- swyx 7y agook so... why is writing an AST more ergonomic than having some syntax?
- _hardwaregeek 7y agoIt’s really not. That’s part of the problem with lisp. But you can treat your code as a data structure which offers a lot of benefits. For instance, it’s basically impossible to offer control flow as a library in normal languages. That is, if you wanted to implement an unless statement like in Ruby, you’d have to use thunks or some other form of lazy evaluation. Macros allow you to just transform the unless statement into an if statement quite easily by just operating on the AST. Of course, you can do this without homoiconicity but it’s a lot less ergonomic. Also part of the reason Babel exists is to take the place of a macro system. Instead of transpiling array spread into a function polyfill, macros would just output the pollyfill into the AST. What’s nice about this is that since it’s userland, people can test drive new features. Rust did that for async/await. And the pattern matching proposal in JS is based off a SweetJS macro. (Obviously not all language features can be implemented as macros but you get my point, right)
- swyx 7y agoi think so. thanks for the explainer!
- christophilus 7y agoThat’s a fair description of the syntax, but Clojure is more than just syntax.
- swyx 7y agowhats the key piece missing for you then? because my friend was definitely very keen on the "no syntax" bit
- iLemming 7y agoREPL. homoiconicity makes "real" REPL possible. Anyone who hasn't tried Lisp would say: "a lot of other [non-lispy] languages have REPLs". But only after trying Lisp REPL you can truly experience why is it so special. It is extremely liberating to be able to evaluate any part of your [running] program, anytime, [almost] without any preceding ceremony. Even famous Jupyter Notebooks fall short in comparison.
- lispm 7y ago> It is extremely liberating to be able to evaluate any part of your [running] program, anytime, [almost] without any preceding ceremony. Sounds like Smalltalk.