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

8.8k views Asked by At

It seems to me that technically both are interchangeable but have different conventional meanings.

1

There are 1 answers

1
Theodoros Chatzigiannakis On BEST ANSWER

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.