The Bracket Invasion

The programming language Scheme is often used to teach programming language concepts. One of its most idiosyncratic properties is the fully parenthesized syntax that dialects of Lisp share. This syntax employs parentheses excessively—to an extent that scares many newcomers to the language. Though most experienced users use the parentheses as a help for grouping expressions so that their editor gets the indentation right, to express structure, and don't really see the parentheses themselves anymore, teachers have devised a system that allows the usage of square brackets instead of parentheses in Scheme. Alternating both kinds, they claim, makes reading the language much easier.

In a recent post to comp.lang.scheme, Anton van Straaten gave some examples of such code:

The usual convention for use of square brackets is in cases where the bracketed expressions don't represent a procedure application. Instead, the brackets are used to delimit groups of expressions in a macro, to make the groups easier to distinguish visually. They also tend to reduce ambiguity, which can help an automated paren matcher match more intelligently.

A couple of typical examples:

(cond
  [(foo) (bar)]
  [(baz)
   (quux ziiy)]
  [else (blurk!)])

(let-values ([(f g) (get-two-values)]
             [(a b c) (get-three-values)]
             [(h) (get-value)])
  (list a b c f g h))

Agreeing with many experienced Scheme users, I claim that this makes code less readable. I even prefer the following style, with dimmed parentheses.

(cond
  ((foo) (bar))
  ((baz)
   (quux ziiy))
  (else (blurk!)))

(let-values (((f g) (get-two-values))
             ((a b c) (get-three-values))
             ((h) (get-value)))
  (list a b c f g h))

I sympathize with Pascal Bourguignon when he says that he “prefer[s] to use only parentheses and let emacs do the indentation and parenthesis checking for [him]”, but go even further, as my reply states.

The code found in that posting has been tidied up and published as bracketphobia.el. And thus, Emacs saves us from the evil Bracket Invasion from outer space. May it save you, too.