Why does Jane Street use s-expressions so much?

I’ve played with Jane Street libraries quite extensively and basically use the Sexp library daily. Recently, I’ve notice that I use the dune action DSL and noticed that dune expressions are giant s-expression. Then, I found myself using shexp, which is another s-expression DSL. I was kind of curious why does Jane Street like using s-expressions to express their data types and their DSLs.

Unofficial short answer: 'cause sexps are really easy to parse and also represent.

If you drank the Lisp kool-aid, perhaps in the salad days of your youth, you remember that type t = Atom of string | List of t list is all the structure you need to usher in the whole universe. Using sexps may bring you back to fond childhood places.

More practically, sexps make a good configuration language (especially when supplemented with Blang), the two text editors already have modes for them, and if you’re using a third-party tool/system that doesn’t understand them you can crush out an ad hoc sexp parser pretty quickly.

Be sure to get familiar with the sexp swiss-army knife tool while you’re at it. At least so you can sexp pp in a shell pipeline.

1 Like

What attributes do we want in a data-interchange language?

  1. easily parseable/pretty-printable by all the programming languages we use
  2. easily manipulable by code
  3. human-readable/writable
  4. very general, no obvious limitations (typically “fully tree-recursive syntax”)

In the Before Time (pre-1995) there was really only one such language: s-expressions. Then came XML, which taught us what not to do. And since then, we’ve had many new languages: YAML, JSON, INI (fails #4), “protobufs text-mode”. Probably others. In truth, s-expressions fails #1. But if you’re pretty much an Ocaml shop, and many of your leaders came from (or were educated in) LISP/Scheme, then #1 isn’t realy a problem, is it?

These days, I typically go with JSON, b/c there are nice C++ JSON parsers (and of course, in every GCed language on Earth). But if I only cared about Ocaml, it’s not clear why s-expressions aren’t already enough. They’re certainly more compact than JSON, and that’s its own virtue.

P.S. Why #3? Because if I choose wisely, I can avoid writing any other parsers at all: I can use this one data-interchange language for all my configuration-files, all my “little languages”, etc. There are limitations to this approach, but it’s got tremendous power.

3 Likes