Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Colon (punctuation)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Programming languages=== {{See also|Semicolon#Computing usage}} Many programming languages, most notably [[ALGOL]], [[Pascal (programming language)|Pascal]] and [[Ada (programming language)|Ada]], use a colon and equals sign {{code|1=:=}} as the [[assignment (computer science)|assignment operator]], to distinguish it from a single equals {{code|1==}} which is an equality test ([[C (programming language)|C]] instead uses a single equals as assignment, and a double equals {{code|1===}} as the equality test).<ref>{{cite web |url=https://wiki.freepascal.org/Becomes |title=Becomes |website=Free Pascal and Lazarus Wiki |date=4 February 2021 |archive-date=2 March 2022 |archive-url=https://web.archive.org/web/20220302024707/https://wiki.freepascal.org/Becomes |url-status=live}}</ref><ref>{{cite web |url=http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-5-2.html |title=Ada Reference Manual – 5.2 Assignment Statements |publisher=Ada Conformity Assessment Authority |year=2012 |archive-date=20 May 2020 |archive-url=https://archive.today/20200520204221/http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-5-2.html |url-status=live}}</ref> Many languages including [[C (programming language)|C]] and [[Java (programming language)|Java]] use the colon to indicate the text before it is a [[label (computer science)|label]], such as a target for a [[goto]] or an introduction to a case in a [[switch statement]].<ref name='c99'>{{cite web |author=ISO/IEC JTC1/SC22/WG14 |date=7 September 2007 |url=https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf |title=ISO/IEC 9899:TC3 – Programming languages – C |archive-date=16 April 2020 |archive-url=https://archive.today/20200416164053/http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf |url-status=live}}</ref>{{rp|p=131}}<ref>{{cite web |url=https://docs.oracle.com/javase/specs/jls/se18/html/jls-14.html |title=The Java Language Specification – Chapter 14. Blocks, Statements, and Patterns |website=Oracle Help Center |date=23 February 2022 |publisher=Oracle |archive-date=8 June 2022 |archive-url=https://web.archive.org/web/20220608143908/https://docs.oracle.com/javase/specs/jls/se18/html/jls-14.html |url-status=live}}</ref> In a related use, [[Python (programming language)|Python]] uses a colon to separate a control statement (the ''clause header'') from the block of statements it controls (the ''suite''):<ref>{{cite web |title=The Python Language Reference – 8. Compound statements |date=22 January 2016 |publisher=Python Software Foundation |url=https://docs.python.org/3/reference/compound_stmts.html |url-status=live |archive-url=https://archive.today/20160126080617/https://docs.python.org/3/reference/compound_stmts.html |archive-date=26 January 2016}}</ref> <syntaxhighlight lang="python"> if test(x): print("test(x) is true!") else: print("test(x) is not true...") </syntaxhighlight> In many languages, including [[JavaScript]], colons are used to define [[name–value pair]]s in a [[JSON|dictionary]] or [[Object (computer science)|object]].<ref>{{cite book |author=ECMA TC39 |title=ECMA-262 |edition=13th |publisher=Ecma International |date=June 2022 |url=https://www.ecma-international.org/wp-content/uploads/ECMA-262_13th_edition_june_2022.pdf |archive-date=4 July 2022 |url-status=live |archive-url=https://web.archive.org/web/20220704012713/https://www.ecma-international.org/wp-content/uploads/ECMA-262_13th_edition_june_2022.pdf}}</ref>{{rp|pp=96–100}} This is also used by data formats such as [[JSON]].{{Ref RFC|8259}} Some other languages use an equals sign. <syntaxhighlight lang="javascript"> var obj = { name: "Charles", age: 18, } </syntaxhighlight> The colon is used as part of the [[?:]] conditional operator in C and many other languages.<ref name='c99'/>{{rp|p=90}} [[C++]] uses a double colon as the [[scope resolution operator]], and [[class member function|class member access]].<ref>{{cite web |url=https://en.cppreference.com/w/cpp/language/identifiers |title=Identifiers |website=C++ Reference |date=16 June 2022 |archive-date=22 July 2022 |archive-url=https://web.archive.org/web/20220722004426/https://en.cppreference.com/w/cpp/language/identifiers |url-status=bot: unknown |access-date=28 July 2022}}</ref> Most other languages use a period but C++ had to use this for compatibility with C. Another language using colons for scope resolution is [[Erlang (programming language)|Erlang]], which uses a single colon.<ref>{{cite web |url=https://www.erlang.org/doc/reference_manual/expressions.html |title=Erlang Reference Manual – Expressions |website=Erlang |date=15 July 2022 |publisher=Ericsson |archive-date=21 July 2022 |archive-url=https://web.archive.org/web/20220721195015/https://www.erlang.org/doc/reference_manual/expressions.html |url-status=bot: unknown |access-date=28 July 2022}}</ref> In [[BASIC]], it is used as a separator between the statements or instructions in a single line. Most other languages use a semicolon, but BASIC had used semicolon to separate items in print statements.<ref>{{cite web |url=https://docs.microsoft.com/en-gb/dotnet/visual-basic/programming-guide/program-structure/special-characters-in-code |title=Special Characters in Code (Visual Basic) |website=Microsoft Docs |publisher=Microsoft |date=15 September 2021 |archive-date=11 April 2022 |archive-url=https://web.archive.org/web/20220411195955/https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/special-characters-in-code |url-status=live}}</ref> In [[Forth (programming language)|Forth]], a colon ''precedes'' definition of a new word.<ref>{{cite web |url=https://forth-standard.org/standard/core/Colon |title=Core: Glossary |website=Forth Standard |publisher=Forth-Standard-Committee |archive-date=17 November 2015 |archive-url=https://web.archive.org/web/20151117054836/https://forth-standard.org/standard/core/Colon |url-status=live}}</ref> [[Haskell]] uses a colon (pronounced as "[[cons]]", short for "construct") as an operator to add a [[data element]] to the front of a [[List (computing)|list]]:<ref>{{cite book |last1=O'Sullivan |first1=Bryan |last2=Stewart |first2=Don |last3=Goerzen |first3=John |date=2007–2008 |title=Getting Started |url=https://book.realworldhaskell.org/read/getting-started.html |publisher=Real World Haskell |access-date=8 November 2011 |url-status=live |archive-url=https://archive.today/20120710090552/http://book.realworldhaskell.org/read/getting-started.html |archive-date=10 July 2012}}</ref> <syntaxhighlight lang="haskell">"child" : ["woman", "man"] -- equals ["child","woman","man"]</syntaxhighlight> while a double colon <code>::</code> is read as "has type of" (compare [[Scope resolution operator#Haskell|scope resolution operator]]):<ref>{{cite book |first1=Miran |last1=Lipovača |date=April 2011 |url=https://learnyouahaskell.com/types-and-typeclasses |chapter=Types and Typeclasses |title=Learn You a Haskell for Great Good! |publisher=No Starch Press |isbn=978-1593272838 |access-date=8 November 2011 |archive-date=10 July 2012 |archive-url=https://archive.today/20120710015700/http://learnyouahaskell.com/types-and-typeclasses |url-status=live}}</ref> <syntaxhighlight lang="haskell">("text", False) :: ([Char], Bool)</syntaxhighlight> The [[ML (programming language)|ML]] languages (such as [[Standard ML]]) have the above reversed, where the double colon (<code>::</code>) is used to add an element to the front of a list; and the single colon (<code>:</code>) is used for type guards.<ref>{{cite book |last1=Milner |first1=Robin |author1-link=Robin Milner |last2=Tofte |first2=Mads |author2-link=Mads Tofte |last3=Harper |first3=Robert |author3-link=Robert Harper (computer scientist) |first4=David |last4=MacQueen |title=The Definition of Standard ML |edition=Revised |publisher=MIT Press |year=1997 |isbn=0-262-63181-4 |url=https://smlfamily.github.io/sml97-defn.pdf |archive-date=30 April 2020 |url-status=live |archive-url=https://web.archive.org/web/20200430075159/https://smlfamily.github.io/sml97-defn.pdf}}</ref>{{rp|pp=20, 70}} [[MATLAB]] uses the colon as a binary operator to generate a vector, or to select a part of an extant matrix. [[APL (programming language)|APL]] uses the colon: * to introduce a [[Control flow|control structure]] element. In this usage it must be the first non-blank character of the line.<ref name="DyalogAPL">{{cite web |url=http://docs.dyalog.com/13.0/Dyalog%20APL%20Language%20Reference.v13.0.pdf |title=Dyalog APL Language Reference Manual |access-date=14 February 2012 |date=April 2011 |publisher=Dyalog Limited |archive-date=4 March 2016 |archive-url=https://web.archive.org/web/20160304040415/http://docs.dyalog.com/13.0/Dyalog%20APL%20Language%20Reference.v13.0.pdf |url-status=live}}</ref>{{Rp|p=64}} * after a label name that will be the target of a <code>:goto</code> or a right-pointing arrow (this style of programming is deprecated and programs are supposed to use control structures instead).<ref name="DyalogAPL"/>{{Rp|p=64}} * to separate a guard ([[Boolean expression]]) from its expression in a dynamic function.<ref name="DyalogAPL"/>{{Rp|p=111}} Two colons are used for an Error guard (one or more error numbers).<ref name="DyalogAPL"/>{{Rp|p=115}} * Colon + space are used in class definitions to indicate inheritance.<ref name="DyalogAPL"/>{{Rp|p=135}} * ⍠ (a colon in a box) is used by APL for its variant operator.<ref name="DyalogAPL"/>{{Rp|p=340}} The colon is also used in many operating systems commands.<ref>{{cite web |url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#colon |title=colon – null utility |website=IEEE Std 1003.1-2017 |year=2018 |publisher=The Open Group |archive-date=17 October 2018 |archive-url=https://archive.today/20181017145503/http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html |url-status=live}}</ref> In the [[esoteric programming language]] [[INTERCAL]], the colon is called ''two-spot'' and used to label a [[32-bit computing|32-bit]] variable, distinct from ''spot'' (.) to label a [[16-bit computing|16-bit]] variable.<ref>{{cite web |last1=Woods |first1=Donald R. |author1-link=Don Woods (programmer) |last2=Lyon |first2=James M. |year=1973 |url=http://oops.se/~urban/pit/intercal.ps |format=PS |url-status=dead |archive-url=https://web.archive.org/web/20110716084816/http://oops.se/~urban/pit/intercal.ps |title=INTERCAL reference manual |archive-date=2011-07-16 |access-date=2012-03-10}}</ref>{{Rp|p=3}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)