The problem with Clojure's type hints and Arc's if statement

Arc's (if ) statement has the same function as the classical Lisp (cond ) statement, but the parentheses around the conditional blocks have been dropped with the intention of condensing the code. For example, where in Scheme one writes

(cond ((= x 1) (do-this))
      ((= x 1) (do-something))
      (else (alternatively)))

The Arc equivalent is

(if (= x 1) (do-this) 
    (= x 1) (do-something) 
    (alternatively)

A form with fewer parentheses. These parentheses weren't decorative though, they exposed the structure of the code, and they are a minimal price to pay for extra clarity.

Recently I have been finishing off a clojure mode for Lisping, my iPad lisp editor, and I noticed a similar problem with Clojure's let bindings and argument lists whilst writing the auto-layout algorithms. The Scheme let statement

(let ((x 1)
      (y 2))
  (body-goes-here))

becomes

(let [x 1
      y 2]
  (body-goes-here))

Once again, without parentheses around the bindings, the code requires much more careful formatting for the sense to be clear. This problem is exacerbated by Clojure's optional type hints where there need not even be an equal number of elements in each line.

(let [^String x "x string"
      y 2]
  (body-goes-here))

JavaScript minifiers are a convincing argument that any code requires some formatting for the structure to be clear, but for me the line between Python and Brainfuck is drawn when there are no longer syntactic elements visually delimiting the structure of the code. By dropping these parentheses around bindings, Arc and Clojure are toeing that line.

The rationale in both cases is to reduce the quantity of parentheses, which seems a good idea given how they deter prospective Lispers, but Lisp's longevity and its unique slot in the world of programming languages stems from the straightforward correspondence between the parse tree and the source code, and to retain that these parentheses around bindings need to stay.

As a side note, in the case of Arc dropping these delimiters is a false economy because without parentheses around the (if ) clauses one must insert (do ) statements to include a sequence of S Expressions inside the (cond) clause.

This isn't a serious criticism of Clojure; it certainly won't stop me using it and I think it is a shame that Arc died young, but without sounding like someone who believes we should all be coding on Genera, I do think it is important for the new Lisps to retain the features that have made Lisp a language worth reinventing 55 years after its first appearance.

Posted on 29 May 2012

Based on a work at http://slidetocode.com/blog

Slide to code blog is licensed under a Creative Commons Attribution 3.0 Unported License