This paper covers the history and use of parentheses in programming languages, from the beginning of programming to the present day. Early programming languages only had round parentheses, but later keyboards added brackets and braces.

 

Parentheses....................................................................................................................................................................... 1

Lisp Super Parentheses............................................................................................................................................... 2

New Parentheses.......................................................................................................................................................... 2

Parentheses

 

Copyright Dennie Van Tassel 2004.

Please send suggestions and comments to dvantassel@gavilan.edu

 

The use of parentheses has changed as input devices added more types of parentheses. The early IBM keypunch machines only had the standard round (   ) parentheses. So these were used for several different unrelated purposes:

 

            y = prices(i)             // parentheses used for array prices

            x = sqrt(y)               // parentheses used for square root function

            w = cost(k)               // array or function – which is it?

            x = b + (2.0/3.0)       // parentheses used for grouping expressions

            (* check this *)        // comments in early Pascal.

 

This caused many problems since it was often difficult for the compiler or a programmer to tell if an array or function was being used. Many a beginning FORTRAN programmer, after spelling an array wrong, wondered why the compiler kept telling him that something was wrong with his function since he did not know he had one.

 

Since early C developers were recovering FORTRAN programmers, they had seen this error and adopted square brackets [ ] for arrays, which had recently appeared on keyboards

 

     y = a[i];     // array a.

     x = sqrt(y)   // square root function.

 

So the C family of languages has continued to use this way to indicate array subscripts. Perl has figured out a different way to indicate arrays. Look at Perl section in the Array chapter.

 

Now we just have the problem left where a beginning student tries to use implied multiplication, like m = b(c+4) and again gets that puzzling error message about array b. She should have used m = b*(c+4).

 

ALGOL used beginend for their block structure, but C adopted the briefer curly braces { … } which had then appeared on input devices. Like this decision, most decisions in C favored brevity. Earlier languages did not have that choice.

 

The C language pattern of parentheses use has prevailed in most modern languages:

 

            (   )       Use for functions.

            [   ]       Use for arrays.

            {   }     Use for blocks.

            <   >     Use for comparisons.

 

But a few languages have added some interesting twists to this use.

 

Lisp Super Parentheses

In most languages parentheses have to be matched ‑ an equal number of open and closing parentheses, but this is not always true. In Lisp, a language that is very parentheses hungry, there are a couple inventions. First, Lisp uses a lot of parentheses, so when you want to close something, Lisp allows you to just put a bunch of closing parentheses, and as long as there are enough closing or too many, no error message is generated. Here is a Lisp example: 

 

   (defun factorial (x)

      (if (eql x 0)

        1

        (* x (factorial (- x 1))))) ))

 

Thus in the above last line, we just added a few extra closing parentheses, and Lisp will use as many as necessary. If you do not like that method, then Lisp has the super parentheses, which is a closing super right bracket, which makes up for how ever many closing round parentheses you need. Here is the same example with that technique:

 

   (defun factorial (x)

      (if (eql x 0)

        1

        (* x (factorial (- x 1))  ]

 

Since we want to end the function and are not sure how many closing parentheses we need, we just add a square bracket to make up for any missing parentheses.

 

New Parentheses

Some languages have invented “new parentheses”. These parentheses are made up of several characters or composite characters. This is done by using two characters. Ada uses two angle brackets to enclose labels a follows:

 

   <<process_errors>>

 

Maybe this is Ada’s way to show that goto’s and labels are bad.

 

The Web languages have spawned other new parentheses. HTML uses

 

   <!-- comments here -->

 

So we might say "<!--" is a  new start parentheses and "-->" is the closing parentheses.

 

XML has added a few more. The most interesting one is the following:

 

<![IGNORE[

  <!—The following are temporarily deactivated

      . . .

]]>

 

These are some complicated sets parentheses, if we wish to call them that. This last one is explained in the Comments chapter.

 

 


]

Lisp super bracket, 2

]]>

XML, 3

{

blocks, 1

<!--

HTML, 3

<![IGNORE[

XML, 3

<<

Ada, 2

-->

HTML, 3

Ada

labels, 2

angle brackets, 2

array

parenthesis, 1

bracket

Lisp, 2

curly braces, 1

IBM keypunch machines, 1

IGNORE, 3

Lisp

parentheses, 2

parentheses

arrays, 1

functions, 1

input devices, 1

super, 2

super parentheses, 2


 

 

This file is from www.gavilan.edu/csis/dvantassel/languages/parentheses.html

Date last revised July 8, 2004.

Copyright Dennie Van Tassel, 2004.

Send comments or suggestions to dvantassel@gavilan.edu

I am especially interested in errors or omissions and I have other chapters on History of Programming Languages.

 

Hits: