Using S-expressions for fun and profit

Hi, I’m sorry that I’m spamming the forum with silly questions, but I had a thought and wanted to ask if any folks were using this in production.

I am working on an app which uses Dream and thinking about producing an API. I was thinking about how I could design the API, using JSON or whatever, and I thought, why not just use S-expressions?

A lot of my use case for accessing this API is through Emacs, so this seems particularly appropos.

I’m using Caqti right now to do my postgres connection. I was also wondering if I could even get raw sexps from my database to use in my program logic. That seems like it would work nicely, it would make it super easy to expose API endpoints, and it just seems fun.

I guess you would lose the list iteration features in Caqti. I’m not very good with OCAML so I don’t know what the other consequences would be.

If I understand correctly, there’s not really native language support for them, but Base and Core seem to like them.

found a couple examples of people doing this online, and people seem to universally hate the idea.

Asking questions when using OCaml is what the forum is for.

It depends a bit on how you intend to use your API. If the API is private to your own system then use whatever you feel using.

Problems starts if you intend your API to be used by other systems:

  • In a browser, which has a built-in JSON parser and maps data in the native language without any work, people are indeed going to hate the idea: they had no parsing and data mapping problem and you just gave them one :–)
  • There is no s-expression standard and no universal agreed upon way to encode dictionnaries.

Personally as a former lisper I was attracted for a long time to s-expressions, but nowadays I don’t think I would ever use it for either serialization or configuration.

2 Likes