Over the past few weeks, I’ve spent some intensive time on Disp, a programming language that looks syntactically like lisp, with the goal of making managing large codebases easier.

There’s a lot of ideas that went into it’s design, so I wanted to lay them out in a series here. I’m looking for feedback, so don’t hesitate to reply back if you disagree or have ideas. Also please check out the RFCs and leave some thoughts.

This first series is around the choice of lisp + indentation. Specifically, disp syntax looks something like:

https://gist.github.com/toumorokoshi/d19d68176e0ef63c255c9aea6475dac9

(no highlighting unfortunately, Disp is it’s own fun syntax).

It’s very lisp-like: you’ll see the standard parens, which represent a function invocation. But you also see that some parens are missing, and indentation exists instead.

There are two extra rules to manage these syntactical changes:

  • every newline is considered an implicit expression

  • indentation means that you are providing a list to the previous, less indented statement.

It means the following two forms are identical to the parser:

https://gist.github.com/toumorokoshi/922b919768ed7d029ce22fdb044a3ca2

to help reduce the parentheses, every statement on a new line is considered to be an expression, and a list as an argument can be represented with an indented block.

There were a couple reasons for this choice:

Readability #

A major complaint with lisp is the number of parentheses required, making it hard to see where parentheses begin and where they end. Lisp experts say that you get used to it and it’s not a major issue in the long run. There are also plugins for many editors that match the parentheses using colors, that helps as well.

However, considering the language will be responsible for the parsing anyway, it seemed intuitive to remove unneeded symbols if the purpose could still be clear to a reader. The easiest removal was the surrounding of parenthesis on a newline statement: at that point, the syntax looks very similar to a non-lisp based programming language:

https://gist.github.com/toumorokoshi/f2a2ed1f06b141d60b71b3671c08fb45

The indentation rules enable an almost python-like syntax: in many cases a block is represented by a list of statements or expressions, so allowing one to enumerate results in a similar level of readability, as far as expressions go:

https://gist.github.com/toumorokoshi/6ea506cb807f5cc2968d331f02e1c3a0

https://gist.github.com/toumorokoshi/6ea506cb807f5cc2968d331f02e1c3a0?ts=2

https://gist.github.com/toumorokoshi/ca24024d90ac0d9aecee534420aa1d01?ts=2

Semantic Indentation for Consistency #

Many languages are moving to the single-idiomatic formatting paradigm, which does a great job of quelling style discussions which ultimately have minor benefits for the reader, but consume a large amount of time. I think this is a must for a language for large organizations, and Disp continues in that vein.

Adding semantic meaning to indentation is almost a self-fulfilling prophecy: by adding semantic meaning style becomes more consistent, and it’s possible to add semantic meaning to indentation because style is consistent. It would be a waste to not use it to semantically.

Indentation is also used to improve readability and denote blocks of code in most styleguides, so it’s not a far stretch to use it as such.

Tabs instead of Spaces for Indentation #

I’m sure this choice is a bit more controversial, but Disp uses tabs for indentation, instead of spaces (unfortunately many code snippets here use spaces because it’s hard to type tabs in browser).

There are many different flavors of indentation to choose from. Python, for example, is extremely lenient and allows one to use a mix of both. In the name of consistency and simplified parsing, it made sense to choose a single one.

Tabs was chosen to allows developers to modify the tab width settings in their IDE, choosing the spacing that is more legible to them.

Conclusion #

Thanks for reading! I’m looking for any help to improve the readability or remove unneeded syntax. There’s more in this series coming up, so stay tuned.