What is the difference between [ ] and ( ) brackets in Racket (lisp programming language)?

According to the Racket documentation, there is no difference — there is only a convention to use [ and ] for cond clauses (and use your judgement for the rest, as far as I understand):

The use of square brackets for cond clauses is a convention. In Racket, parentheses and square brackets are actually interchangeable, as long as ( is matched with ) and [ is matched with ]. Using square brackets in a few key places makes Racket code even more readable.

Without having any knowledge about the design of the Racket language, my guess would be that square brackets were introduced as a response to complaints that many Lisp expressions are hard to read due to the large number of identical-looking parentheses, especially at the ends of deeply nested constructs. In other words, it’s probably used to allow your eye to easily establish some points of reference in the code to identify what bracket you’re closing at any given point.

Leave a Comment