As discussed in the [Problem] page, many developers find standard Lisp notation hard to read. Early Lisp was even harder to read, so abbreviations were added; one example is being able to abbreviate (quote x) as 'x. Our approach is to add additional abbreviations for common cases, so that expressions in any Lisp-based language will be even easier to read. Well-formatted S-expressions should work as-is, but if you use our abbreviations, the result should be easier for humans to understand.
Unlike most past efforts to make Lisp more readable, our approach is generic (the notation does not depend on an underlying semantic) and homoiconic (the underlying data structure is clear from the syntax). We believe these are necessary conditions for a readable Lisp notation. Previous efforts, like McCarthy's M-expressions, failed because they lacked these properties.
We have three notation tiers, each of which builds on the previous one. Curly-infix starts with traditional s-expressions and adds support for traditional infix notation; neoteric-expressions add support for traditional function notation; and sweet-expressions reduce the number of explicit parentheses needed (by deducing them from indentation).
You do not need to use all three tiers. In particular, if you don't want to use an indentation-sensitive language, you don't need to.
Here's the complete specification of these abbreviations (where "⇒" means "maps to"):
Sweet-expressions (t-expressions): Includes neoteric-expressions, and deduce parentheses from indentation. Here are the basics:
Sweet-expression rule clarifications:
Sweet-expressions also include these advanced capabilities:
Sweet-expression examples are shown below. For Scheme, sweet-expressions are defined in SRFI 110.
See [Rationale] for why these rules are the way they are, and [Retort] if you were told that Lisp's s-expression notation can't be improved on.
Beginning an expression with indentation causes that line's indentation to be ignored, improving backwards compatibility. We recommend that editors highlight these lines as warnings, to reduce the risk of their accidental use. It might be also useful for an editor to highlight blank lines (as they separate expressions) and lines beginning at the left column.
Our goal is to devise general abbreviations that others can build on if they choose. Individual implementations may have additional abbreviations that are useful for their semantics, or extensions to the rules listed above. For example, the Scheme and Common Lisp sample implementations of sweet-expressions also implement line continuation (use "\\" at the end of a line, after at least one expression, and the next line will be a continuation if it has at least the same indentation level).
This is version 1.0 of our notation specification.
Here are some examples of the result, as well as what they map to (which is what you would have had to type before):
Sweet-expression | (Awkward) S-expression |
---|---|
define fibfast(n) if {n < 2} n fibup(n 2 1 0) |
(define (fibfast n) (if (< n 2) n (fibup n 2 1 0))) |
define fibup(max count n1 n2) if {max = count} {n1 + n2} fibup max {count + 1} {n1 + n2} n1 |
(define (fibup max count n1 n2) (if (= max count) (+ n1 n2) (fibup max (+ count 1) (+ n1 n2) n1))) |
define factorial(n) if {n <= 1} 1 {n * factorial{n - 1}} |
(define (factorial n) (if (<= n 1) 1 (* n (factorial (- n 1))))) |
Notice that infix operations and function calls are much easier to read, and notice how much easier it is to read when there are fewer parentheses. Now you don't need to use indentation tools to keep the code indented correctly; the indentation is part of the code itself.
See the [Examples] page for many more examples, including with Lisp macros (they work just fine).
The code distribution comes with "sweeten.sscm"; this is a program that translates traditional S-expressions into sweet-expressions, and is itself written using sweet-expressions.
"Letterfall" by Alan Manuel Gloria is a game written using sweet-expressions; you can see it here: https://github.com/AmkG/letterfall
Here are some advantages of these notations:
Also, thanks to the many other mailing list participants who provided feedback.
Read the [Install-howto] to learn how to install the software. [Prepackaged] lists some cases where the software is prepackaged for your use.
Then look one of our two tutorials:
We think you'll like these notations once you try them.
Wiki: Common-lisp-tutorial
Wiki: Examples
Wiki: Goals
Wiki: Home
Wiki: Hubris
Wiki: Install-howto
Wiki: Join
Wiki: Modifications-0.3
Wiki: Names
Wiki: Prepackaged
Wiki: Problem
Wiki: Rationale
Wiki: Retort
Wiki: Scheme-tutorial