It seems to me that technically both are interchangeable but have different conventional meanings.
Square brackets in the grammar indicate a parenthesized sequence of forms, where square brackets are normally used (by convention).
square bracket is used for indexing an array/list/dict, round brackets are used in function calls.
Brackets, or braces, are a syntactic construct in many programming languages. They take the forms of "[]", "()", "{}" or "<>." They are typically used to denote programming language constructs such as blocks, function calls or array subscripts. Brackets are also known as braces.
A vertical bar that separates two or more elements indicates that any one of the elements can be typed. < > Bold angle brackets are part of the syntax, and must be typed unless indicated otherwise. ( ) Bold parentheses are a part of the syntax.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With