Caret#Programming languages

{{Short description|Typographical mark (^)}}

{{hatgrp|{{About|the computing character|the proofreader's insertion symbol|Caret (proofreading)|other uses}}

{{distinguish|Carrot|Carat (disambiguation){{!}}Carat}}}}

{{redirect2|^|U+005E|the diacritic|circumflex|math notation|Exponentiation|and|Logical conjunction|similar characters sometimes called "caret"|Wedge (symbol){{!}}∧|and|Lambda{{!}}λ|and|Radical 9{{!}}人|and|Turned v{{!}}ʌ}}

{{Use dmy dates|date=June 2023}}

{{infobox symbol

|mark = ^

|name = Caret

|unicode = {{unichar|005E|Circumflex accent|html=|nlink=Circumflex}}

|different from= {{unichar|2038|Caret|nlink=Caret (proofreading)}}
{{unichar|02C6|Modifier letter circumflex accent|nlink=Circumflex}}
{{unichar|028C|Latin small letter turned v|nlink=Turned v}}
{{unichar|2227|Logical AND |nlink=Logical conjunction}}
{{unichar|039B|GREEK CAPITAL LETTER LAMDA}}

|see also= {{unichar|FF3E|Fullwidth circumflex accent|html=}}

}}

{{wiktionary|caret}}

Caret ({{etymology|la|caret|there is lacking}}){{cite web

|url=https://www.etymonline.com/word/caret

|title=Etymology of 'caret'

|website=Online Etymology Dictionary

|access-date=22 October 2024

|publisher=Douglas Harper

}} is the name used familiarly for the character {{char|^}} provided on most QWERTY keyboards by typing {{key press|shift|6}}. The symbol has a variety of uses in programming and mathematics. The name "caret" arose from its visual similarity to the original proofreader's caret, {{char|‸}}, a mark used in proofreading to indicate where a punctuation mark, word, or phrase should be inserted into a document. The ASCII standard (X3.64.1977) calls it a "circumflex";{{cite web |url=https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-1977.pdf |title=American National Standard for Information Interchange |publisher=National Institute for Standards |date=1977}} (facsimile, not machine readable) the Unicode standard calls it a "circumflex accent", although it is no longer practicable for that purpose.

History

=Typewriters=

File:Write machine.jpg and diaeresis accents have dead keys]]

On typewriters designed for languages that routinely use diacritics (accent marks), there are two possible ways to type these: keys can be dedicated to precomposed characters (with the diacritic included); alternatively a dead key mechanism can be provided. With the latter, a mark is made when a dead key is typed but, unlike normal keys, the paper carriage does not move on and thus the next letter to be typed is printed under the accent. The {{char|^}} symbol was originally provided in typewriters and computer printers so that circumflex accents could be overprinted on letters (as in {{char|ô}} or {{char|ŵ}}).

=Transposition into ISO/IEC 646 and ASCII=

The incorporation of the circumflex symbol into ASCII is a consequence of this prior existence on typewriters: this symbol did not exist independently as a type or hot-lead printing character. The original 1963 version of the ASCII standard used the code point {{tt|0x5E}} for an {{nowrap|up-arrow{{nbsp}}{{char|↑}}}}. However, the 1965 {{nowrap|ISO/IEC 646}} standard defined code point {{tt|0x5E}} as one of five available for national variation,{{efn|ISO{{nbsp}}646 (and ASCII, which it includes) is a standard for 7-bit encoding, providing just 96 printable characters (and 32 control characters). This was insufficient to meet the needs of Western European languages and so the standard specifies certain code points that are available for national variation.}} with the circumflex {{char|^}} diacritic as the default and the up-arrow as one of the alternative uses.{{cite web|url=https://jkorpela.fi/latin1/ascii-hist.html#5E|title=Character histories: notes on some ASCII code positions (5E)}} In 1967, the second revision of ASCII followed suit.

{{Image frame|width=150|content={{resize|400%|^â}}|caption=Caret compared to lower-case circumflex accent|align=right}}

Overprinting to add an accent mark was not always supported well by printers, and was almost never possible on video terminals. The freestanding circumflex (which had come to be called a caret) quickly became reused for many other purposes, such as in computer languages and mathematical notation. As the mark did not need to fit above a letter any more, it became larger in appearance such that it can no longer be used to overprint an accent in most fonts. Support for accented characters eventually became to be provided by including precomposed characters in character sets,{{efn|For instance in ISO Latin-1}} rather than by using overprinting.

In Unicode the symbol is encoded as {{unichar|005E}}; in HTML it may be used directly or inserted with {{code|^}}. The combining character for use as a diacritic is {{unichar|0302|cwith=◌}}, although precomposed characters (like {{unichar|00E2}}) are available for most European languages.

Uses

=Programming languages=

The symbol {{char|^}} has many uses in programming languages, where it is typically called a caret. It can signify exponentiation, the bitwise XOR operator, string concatenation{{Citation needed|reason=The majority of programming languages use the plus sign (+) for string concatenation. PHP uses the period (.). I cannot find documentation for any programming languages that indicates a caret (^) is used for string concatenation|date=April 2024}}, and control characters in caret notation, among other uses. In regular expressions, the caret is used to match the beginning of a string or line; if it begins a character class, then the inverse of the class is to be matched.

ANSI C can transcribe the caret in the form of the trigraph {{code|1=??'}}, as the character was originally not available in all character sets and keyboards.

C++ additionally supports tokens like {{code|1=xor}} (for {{code|1=^}}) and {{code|1=xor_eq}} (for {{code|1=^=}}) to avoid the character altogether.

{{IETF RFC|1345}} recommends that the character be transcribed as digraph {{code|1='>}} when required.{{cite web|url=http://tools.ietf.org/html/rfc1345|title=RFC 1345 – Character Mnemonics and Character Sets|date=June 1992 |publisher=Internet Engineering Task Force|access-date=7 March 2022 |last1=Simonsen |first1=Keld }}

Pascal uses the caret for declaring and dereferencing pointers.

In Smalltalk, the caret is the method return statement.

In C++/CLI, .NET reference types are accessed through a handle using the {{code|1=ClassName^}} syntax.

In Apple's C extensions for Mac OS X and iOS, carets are used to create blocks and to denote block types.

Go uses it as a bitwise NOT operator.

Node.js uses the caret in package.json files to signify dependency resolution behavior being used for each particular dependency. In the case of Node.js, a caret allows any kind of update, unless it is seen as a "major" update as defined by semver.{{Cite web |url=https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004 |title=Caret ranges in node.js |access-date=1 October 2019 |archive-date=3 December 2016 |archive-url=https://web.archive.org/web/20161203095427/https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004 |url-status=dead }}

=Surrogate symbol for superscript and exponentiation=

In mathematics, the caret can signify exponentiation (e.g. 3^5 for {{math|35}}) where the usual superscript is not readily usable (as on some graphing calculators). It is also used to indicate a superscript in TeX typesetting.

The use of the caret for exponentiation can be traced back to ALGOL 60,{{citation needed|date=August 2012}} which expressed the exponentiation operator as an upward-pointing arrow, intended to evoke the superscript notation common in mathematics. The upward-pointing arrow is now used to signify hyperoperations in Knuth's up-arrow notation, with a single arrow representing exponentiation and multiple adjacent arrows representing higher-level operations.

=Escape character=

It is often seen in caret notation to show control characters: for instance, {{code|^A}} means the control character with value 1.

The Windows command-line interpreter (cmd.exe) uses the caret to escape reserved characters{{Citation needed|date=December 2024|reason=Citation doesn't mention Caret as quoting character}} (most other shells use the backslash). For example, to pass a 'less-than' sign as an argument to a program, one would type {{code|^<}}.

=Upward-pointing arrow=

In internet forums, on social networking sites such as Facebook, or in online chats, one or more carets may be used beneath the text of another post, representing an upward-pointing arrow to that post; in addition to the arrow usage, it can also mean that the user who posted the ^ agrees with the above post. Multiple carets may be used to indicate that the comment is replying to, or relating to, the post above that correlates with the number of carets used, or to "underscore" the correct portion of the previous post, or simply for emphasis.

A similar use has been adopted by programming language compilers, such as the Java compiler, to point out where a compilation error has occurred.{{citation needed|date=May 2020}} The compiler prints out the faulty line of code and uses a single caret on the next line, padded by spaces, to give a visual indication of the error location.

See also

Notes

{{notelist}}

References

{{Reflist|refs=

{{cite web | title = What is Caret? | url = http://www.computerhope.com/jargon/c/caret.htm | publisher = Computer Hope| access-date = 14 August 2012}}

{{cite web | url = http://www.worldpowersystems.com/projects/codes/index.html#UP | title = ASCII: American Standard Code for Information Infiltration | author = Tom Jennings | access-date = 14 September 2010 | archive-url = https://web.archive.org/web/20140821121342/http://www.worldpowersystems.com/projects/codes/index.html#UP | archive-date = 21 August 2014 | url-status = dead }}

{{cite web| url = https://jkorpela.fi/kirjaimet/tarinoita.pdf | title = Kirjainten tarinoita | author = Jukka K. Korpela | pages = 132–133 | date = 18 January 2010 | access-date = 14 September 2010 | language = fi }}

{{cite web | url = http://unicode.org/charts/PDF/U0250.pdf | title = IPA Extensions | author = Unicode | date = 1991–2012 | access-date = 20 August 2012}}

{{cite web | url = http://mathworld.wolfram.com/Caret.html | title = Caret | author = Eric W. Weisstein | work = MathWorld | publisher = Wolfram | access-date = 20 August 2012 }}

}}

Category:Typographical symbols