Colon (punctuation) - Computing

Computing

In computing, the colon character is represented by ASCII code 58, (HTML :) and is located at Unicode code-point U+003A (colon). Scripts comprising wide characters, such as kanji, use a full-width equivalent, located at Unicode code point U+FF1A : fullwidth colon.

The colon is quite often used as a special control character in URLs, computer programming languages, in the path representation of several file systems (such as HFS), and in many operating systems commands. It is often used as a single post-fix delimiter, signifying a token keyword had immediately preceded it or the transition from one mode of character string interpretation to another related mode. Some applications, such as the widely used MediaWiki, utilize the colon as both a pre-fix and post-fix delimiter.

Several programming languages use the colon for various purposes. In particular, MATLAB uses the colon as a binary operator that generates vectors, as well as to select particular portions of existing matrices. A lot of programming languages, most notably Pascal, and Ada use colon immediately followed by an equality sign, := in which case the colon and the equality sign are considering to compose to an independent assignment sign, in Unicode preferably encoded as U+2254 ≔ colon equals. In BASIC it's used as a separator between the statements or instructions in a single line. In Forth, colon precedes definition of a new word. For the double colon used in computer programming, see the scope resolution operator, and class member access of C++. The colon is also used as part of the ?: conditional operator in C and other languages. In Python, which uses indentation to indicate blocks, the colon is used in statements to indicate that the next line is the start of an indented block.

Haskell uses a colon (pronounced as “cons”, short for “construct”) as an operator to add an element to the front of a list:

"child" : -- returns

while a double colon :: is read as "has type of" (confer scope resolution operator):

("text", False) :: (, Bool)

The ML languages (including Standard ML and OCaml) have the above reversed, where the double colon (::) is used to add an element to the front of a list; and the single colon (:) is used for type guards.

APL uses the colon

  • to introduce a control structure element. In this usage it must be the first non-blank character of the line.
  • after a label name that will be the target of a :goto or a right-pointing arrow (Note: this style of programming is deprecated and programmers are encouraged to use control structures instead.
  • to separate a guard (boolean expression) from its expression in a dynamic function. Two colons are used for an Error guard (one or more error numbers).
  • Colon + space are used in class definitions to indicate inheritance.

Goto labels are formed in a DOS batch file by preceding a label name with a colon.

In an IPv6 address colons (and one optional double colon) separate up to 8 groups of 16 bits in hexadecimal representation. In a URL a colon follows the initial scheme name (like http), and separates a port number from the hostname or IP address.

In JavaScript, colons are used to define values in an object.

var obj = { "name": "Charles", "age": 18 }

Read more about this topic:  Colon (punctuation)