archives

Designing an alternative to s-expressions for language extensibility

While designing my own programming language, I experimented a lot with syntax, but I quickly determined that there are three things I really wanted:

  • I wanted the language to be as extensible as possible: if I wanted to add some control structure like "unless" or transform code arbitrarily with macros, then I should be able to.
  • I wanted syntax as regular as possible and a simple program representation, so that extensions could focus on semantics rather than grammar rules.
  • I wanted the language to look clean and to have little punctuation, similar to Python. I wanted infix operators. S-expressions are regular and simple, but I think they involve too much punctuation and I wasn't willing to compromise on aesthetic preference.

This was an incremental process that I barely documented as I went through it, but in the end I think I came up with something interesting, a kind of syntax that I call o-expressions. I have thought about it a good deal post hoc so that I could explain and justify my findings and I am at a point where I would appreciate some external feedback and criticism. I wrote two blog posts about it:

First, this post describes Liso, a translation of my syntax to s-expressions. It contains many examples, so you can get an intuitive grasp of it. It demonstrates a concrete use as syntactic sugar for Lisp-like languages and I implemented it as a Racket #lang, so you can try it out if you want (source).

My second post is more theoretical. In it I build o-expressions from scratch using principles that I believe are essential to language extensibility.

I plan to keep working on the syntax and port it to other languages, so feedback would be very welcome :)