1. 10
  1. 9

    This reads like a long enumeration of reasons to use clojure in general (macros, code is data is code, etc.), but there’s very little argument about why it’s good for compilers in particular. What makes clojure better suited for that than, say, OCaml or Haskell?

    1. 6

      I find most arguments for X is greating for writing compilers pretty weak, even the more common ones about OCaml/Haskell/Standard ML (and I like both MLs and lisps a lot). Any high-level language is great for writing compilers. As far as I’m concerned, the only ones that aren’t “great” (where “great” means “easy”) are ones where you need to bring your own standard library and do manual memory management (e.g. C).

      1. 2

        You can still talk about why macros, code is data is code, etc are particularly useful to writing compilers. What do they let you do that you couldn’t do otherwise?

        1. 3

          Sure I’m not saying all programming languages are identical. But the awesome parts of languages are awesome no matter what the domain so that’s why I find the arguments about being good for compilers weak as if you can’t easily write compilers in any high level language.

          1. 6

            I think Lisps in particular are so good for writing compilers in particular because they make treating code as data trivial, which is exactly what you want to do in a compiler, because it needs to represent code in a data structure somehow anyway.

            Of course, if the parsing is particularly involved, a Lisp doesn’t offer that much more. It’s mostly useful if you’re using s-expressions throughout. But if you’re not using an s-expression syntax, languages with pattern matching and first class support for ADTs will be at a distinct advantage over languages without those (hence the reason SML is so popular). Optimizations and term rewriting is basically pattern detection and manipulation. A language without first class support for those will give you more friction.

            1. 2

              Part of it is that I don’t like the idea that novice programmers will be turned off by compilers because they always read that sml or clojure or C (or whatever) are great for building compilers and since they don’t know sml or clojure or C it’s not worth trying to build a compiler.

        2. 3

          This is a good talk directly comparing the trade between writing a compiler in Clojure and F#.

          1. 1

            I read this thru earlier and it made very little sense to me. I re-read it and I think what’s going on here is that they’re talking about the fact that using lisp to write a compiler for a lisp is a good fit, but I think they just straight up forgot to say what language it was that they were compiling? Anyway it’s not particularly coherent as-is.

          2. 5

            compilers.

            1. 3

              Lack of static type checking and checks for exhaustive pattern matching leave a lot of room for errors. Having worked on compiler-adjacent (program analysis) tools in both Clojure and Haskell, I would not recommend Clojure for the task. Before switching to Haskell for program analysis projects, I attempted to use spec (and before that Typed Clojure) and unit tests as a replacement for type checking. The result was an ad hoc, informally-specified, bug-ridden, slow implementation of not even half of Haskell’s type system.

              1. 2

                The result was an ad hoc, informally-specified, bug-ridden, slow implementation of not even half of Haskell’s type system.

                I see what you did there. 👏