Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 746
Mahathi Vempati Avatar asked Jan 01 '17 18:01

Mahathi Vempati


People also ask

What do square brackets mean in racket?

Square brackets in the grammar indicate a parenthesized sequence of forms, where square brackets are normally used (by convention).

What is the difference between square brackets and round brackets in Python?

square bracket is used for indexing an array/list/dict, round brackets are used in function calls.

What do brackets mean in programming?

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.

What does brackets mean in syntax?

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.


1 Answers

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.

like image 50
Theodoros Chatzigiannakis Avatar answered Sep 17 '22 03:09

Theodoros Chatzigiannakis