Surround notation

From Esolang
Jump to navigation Jump to search

Surround notation is a lesser known notation, but it is, however, used in many languages. In surround notation, you put the command on both sides of its arguments. One example is parentheses: they are the identity function of surround notation. In xml, the primary notation is surround.

In Perl 6, an operator that uses surround notation is called circumfix.

Examples

In html-style languages:

 <persons>
   <person>
     <name>Qwe Asd</name>
     <age>OVER 9000!!!</age>
   </person>
 </persons>

The general syntax for these kinds of surround operators is <tag></tag>.

In C-style languages:

 while(true) {
   //Do stuff
 }

It is the blocking operator {/*code*/} that is in surround notation. Other examples include array[index] and "string".

In the mathematical notation the absolute value operator |x| is in surround notation.

Uses of surround notation

Surround notation is generally essential for operations with a variable arity. For example, consider the following Python code:

a = ( [1, 2, 3], [-1, -2, -3] ) #a pair of lists with length 3

If the surround notation of the square brackets were omitted, the code would mean something different.

a = ( 1, 2, 3, -1, -2, -3 ) #one hexad of integers

The brackets are therefore required for delimiting an arbitrary number of sequential values from their surroundings.