Operator (computer programming): Difference between revisions

Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
 
(43 intermediate revisions by 9 users not shown)
Line 1:
{{shortShort description|ProgrammingBasic programming language construct that provides functionality that is syntactically different from or not possible to express as a user-defined function}}
{{refimprove|date=January 2019}}
{{About|operators in computer programming|other uses|Operator (disambiguation)}}
 
In [[computer programming]], an '''operator''' is a [[programming language]] construct that provides functionality that may not be possible to define as or has [[Syntax (programming languages)|syntax]] different than a user-defined [[Function (computer programming)|function]] (i.e. Examples[[sizeof]] includein [[InfixC notation(programming language)|infixC]]) or has [[arithmeticSyntax (programming languages)|syntax]] (e.g.different additionthan as <code>a+b</code>), comparisonfunction (ei.ge. [[Greater-thanInfix signnotation|greater thaninfix]] addition as in <code>a&gt;+b</code>), [[Mathematical logic|logic]] (e.g. <code>aLike ANDother b</code>programming orlanguage <code>a&amp;&amp;b</code>)concepts, [[Assignment''operator'' (computerhas science)|assignment]] (e.g. <code>a=b</code> orgenerally <code>a:=b</code>)accepted, [[Recordalthough (computerdebatable science)|record]]meaning oramong [[Objectpractitioners (computerwhile science)|object]]at [[Fieldthe (computersame science)|field]]time accesseach (e.g.language <code>a.b</code>),gives andit [[scopespecific resolutionmeaning operator|scopein resolution]]that (e.g.context, <code>a::b</code>and ortherefore <code>a.b</code>).the Somemeaning languagesvaries allow aby language-defined. operator to be overridden with user-defined behavior.
 
Some operators are represented with symbols {{endash}} characters typically not allowed for a function [[identifier (computer science)|identifier]] {{endash}} to allow for presentation that is more familiar looking than typical function syntax. For example, a function that tests for greater-than could be named <code>gt</code>, but many languages provide an infix symbolic operator so that code looks more familiar. For example, this:
== Syntax ==
Many operators differ syntactically from user-defined functions. In most languages, a function is [[prefix notation]] with fixed [[Order of operations|precedence]] level and associativity and often with compulsory [[parentheses]] (e.g. <code>Func(a)</code> or <code>(Func a)</code> in [[Lisp (programming language)|Lisp]]). In contrast, many operators are infix notation and involve different use of delimiters such as parentheses.
 
<!--this is pseudocode; do not use syntaxhighlight lang="something"-->
In general, an operator may be prefix, infix, postfix, [[matchfix]], [[circumfix]] or bifix<ref>{{Cite web|url=https://reference.wolfram.com/language/tutorial/OperatorInputForms.html.en|title=Operator Input Forms—Wolfram Language Documentation|website=reference.wolfram.com}}</ref><ref>{{Cite web|url=http://maxima.sourceforge.net/docs/manual/maxima_7.html|title=Maxima 5.42.0 Manual: 7. Operators|website=maxima.sourceforge.net}}</ref><ref>{{Cite web|url=https://mythryl.org/my-Prefix__Postfix_and_Circumfix_Operators.html|title=Prefix, Postfix and Circumfix Operators|website=mythryl.org}}</ref><ref>{{Cite web|url=http://doc.perl6.org/language/operators#___top|title=Operators|website=doc.perl6.org}}</ref><ref name=Pribavkina>{{cite book |ref= Pribavkina| last1 = Pribavkina| last2= Rodaro| date= August 2010| year= 2010| title= State Complexity of Prefix, Suffix, Bifix and Infix Operators on Regular Languages |journal= Lecture Notes in Computer Science| type= Conference Article| series= Developments in Language Theory| language= English| edition= 14th International Conference| ___location= London Ontario| publisher= Springer| publication-place= Germany| publication-date= 2010| issue= 6224| pages= 376–377 | doi= 10.1007/978-3-642-14455-4_34| isbn= 978-3-642-14454-7| issn= 0302-9743}}</ref>, and the syntax of an [[expression (computer science)|expression]] involving an operator depends on its [[arity]] (number of [[operand]]s), precedence, and (if applicable), [[Operator associativity|associativity]]. Most programming languages support [[binary operator]]s and a few [[unary operation|unary operators]], with a few supporting more operands, such as the [[?:]] operator in C, which is ternary. There are prefix unary operators, such as unary minus <code>-x</code>, and postfix unary operators, such as [[post-increment]] <code>x++</code>; and binary operations are infix, such as <code>x + y</code> or <code>x = y</code>. Infix operations of higher arity require additional symbols, such as the [[ternary operator]] ?: in C, written as <code>a ? b : c</code> – indeed, since this is the only common example, it is often referred to as ''the'' ternary operator. Prefix and postfix operations can support any desired arity, however, such as <code>1 2 3 4 +</code>.
<code>if gt(x, y) then return</code>
 
Can be:
== Semantics ==
The semantics of operators particularly depends on value, evaluation strategy, and argument passing mode (such as Boolean short-circuiting). Simply, an [[Expression (computer science)|expression]] involving an operator is evaluated in some way, and the resulting [[value (computer science)|value]] may be just a value (an r-value), or may be an object allowing assignment (an l-value).
 
<code>if x > y then return</code>
In simple cases this is identical to usual function calls; for example, addition <code>x + y</code> is generally equivalent to a function call <code>add(x, y)</code> and less-than comparison <code>x &lt; y</code> to <code>lt(x, y)</code>, meaning that the arguments are evaluated in their usual way, then some function is evaluated and the result is returned as a value. However, the semantics can be significantly different. For example, in assignment <code>a = b</code> the target <code>a</code> is not evaluated, but instead its ''___location'' (address) is used to store the value of <code>b</code> – corresponding to [[call-by-reference]] semantics. Further, an assignment may be a statement (no value), or may be an expression (value), with the value itself either an r-value (just a value) or an l-value (able to be assigned to). As another example, the [[scope resolution operator]] :: and the element access operator . (as in <code>Foo::Bar</code> or <code>a.b</code>) operate not on values, but on ''names'', essentially [[call-by-name]] semantics, and their value is a name.
 
Some languages allow a language-defined operator to be overridden with user-defined behavior and some allow for user-defined operator symbols.
Use of l-values as operator operands is particularly notable in unary [[increment and decrement operators]]. In C, for instance, the following statement is legal and well-defined, and depends on the fact that array indexing returns an l-value:
 
Operators may also differ semantically from functions. For example, [[short-circuit evaluation|short-circuit]] Boolean operations evaluate later arguments only if earlier ones are not false.
 
== Differences from functions ==
 
=== Syntax ===
Many operators differ syntactically from user-defined functions. In most languages, a function is [[prefix notation]] with fixed [[Order of operations|precedence]] level and associativity and often with compulsory [[parentheses]] (e.g. <code>Func(a)</code> or <code>(Func a)</code> in [[Lisp (programming language)|Lisp]]). In contrast, many operators are infix notation and involve different use of delimiters such as parentheses.
 
In general, an operator may be prefix, infix, postfix, [[matchfix]], [[circumfix]] or bifix,<ref>{{Cite web|url=https://reference.wolfram.com/language/tutorial/OperatorInputForms.html.en|title=Operator Input Forms—Wolfram Language Documentation|website=reference.wolfram.com}}</ref><ref>{{Cite web|url=https://maxima.sourceforge.net/docs/manual/maxima_7.html|title=Maxima 5.42.0 Manual: 7. Operators|website=maxima.sourceforge.net}}</ref><ref>{{Cite web|url=https://mythryl.org/my-Prefix__Postfix_and_Circumfix_Operators.html|title=Prefix, Postfix and Circumfix Operators|website=mythryl.org}}</ref><ref>{{Cite web|url=http://doc.perl6.org/language/operators#___top|title=Operators|website=doc.perl6.org}}</ref><ref name=Pribavkina>{{cite conference|ref= Pribavkina| last1 = Pribavkina| last2= Rodaro| date= August 2010| title= State Complexity of Prefix, Suffix, Bifix and Infix Operators on Regular Languages |journal= Lecture Notes in Computer Science| type= Conference Article| series= Developments in Language Theory| language= English| conference= 14th International Conference on Developments in Language Theory| ___location= London Ontario| publisher= Springer| publication-date= 2010| issue= 6224| pages= 376–377 | doi=10.1007/978-3-642-14455-4_34| isbn= 978-3-642-14454-7| issn= 0302-9743}}</ref> and the syntax of an [[expression (computer science)|expression]] involving an operator depends on its [[arity]] (number of [[operand]]s), precedence, and (if applicable), [[Operator associativity|associativity]]. Most programming languages support [[binary operator]]s and a few [[unary operation|unary operators]], with a few supporting more operands, such as the [[?:]] operator in C, which is ternary. There are prefix unary operators, such as unary minus <code>-x</code>, and postfix unary operators, such as [[post-increment]] <code>x++</code>; and binary operations are infix, such as <code>x + y</code> or <code>x = y</code>. Infix operations of higher arity require additional symbols, such as the [[ternary operator]] ?: in C, written as <code>a ? b : c</code> – indeed, since this is the only common example, it is often referred to as ''the'' ternary operator. Prefix and postfix operations can support any desired arity, however, such as <code>1 2 3 4 +</code>.
 
=== Semantics ===
The semantics of an operator may significantly differ from that of a normal function. For reference, addition is evaluated like a normal function. For example, <code>x + y</code> can be equivalent to a function <code>add(x, y)</code> in that the arguments are evaluated and then the functional behavior is applied. However, [[Assignment_(computer_science)|assignment]] is different. For example, given <code>a = b</code> the target <code>a</code> is ''not'' evaluated. Instead its value is replaced with the value of <code>b</code>. The [[scope resolution operator|scope resolution]] and element access operators (as in <code>Foo::Bar</code> and <code>a.b</code>, respectively, in the case of e.g. [[C++]]) operate on identifier names; not values.
 
In C, for instance, the array indexing operator can be used for both read access as well as assignment. In the following example, the [[increment and decrement operators|increment operator]] reads the element value of an array and then assigns the element value.
<syntaxhighlight lang=c>
x = ++a[i];
</syntaxhighlight>
 
The C++ <code>&lt;&lt;</code> operator allows for [[fluent interface|fluent]] syntax by supporting a sequence of operators that affect a single argument. For example:
An important use is when a left-associative binary operator modifies its left argument (or produces a [[side effect (computer science)|side effect]]) and then evaluates to that argument as an l-value.{{efn|Conversely a right-associative operator with its right argument, though this is rarer.}} This allows a sequence of operators all affecting the original argument, allowing a [[fluent interface]], similar to [[method cascading]]. A common example is the <code>&lt;&lt;</code> operator in the C++ <code>[[iostream]]</code> library, which allows fluent output, as follows:
<syntaxhighlight lang=cpp>
cout << "Hello" << " " << "world!" << endl;
</syntaxhighlight>
 
== User-definedad operatorshoc polymorphic ==
{{further|Ad hoc polymorphism}}
A language may contain a fixed number of built-in operators (e.g. {{mono|1=+, -, *, &lt;, &lt;=, !, =}}, etc. in [[Operators in C and C++|C and C++]], [[PHP]]), or it may allow the creation of programmer-defined operators (e.g. [[Prolog]],<ref>{{Cite web|url=https://www.swi-prolog.org/pldoc/man?predicate=op/3|title=SWI-Prolog -- op/3|website=www.swi-prolog.org}}</ref> [[Seed7]],<ref>{{Cite web|url=http://seed7.sourceforge.net/examples/operator.htm|title=Declare an operator|website=seed7.sourceforge.net}}</ref> [[F Sharp (programming language)|F#]], [[OCaml]], [[Haskell]]). Some programming languages restrict operator symbols to special characters like {{mono|1='''[[Addition|+]]'''}} or {{mono|1='''[[Assignment (computer science)|:=]]'''}} while others allow also names like <code>[[Integer_division#Division_of_integers|'''div''']]</code> (e.g. [[Pascal (programming language)|Pascal]]).
Some languages provide operators that are '''ad hoc polymorphic''' {{endash}} inherently overloaded. For example, in [[Java (programming language)|Java]] the {{code|+}} operator sums [[number]]s or [[concatenate]]s [[String (computer science)|strings]].
 
== Customization ==
Most languages have a built-in set of operators, but do not allow user-defined operators, as this significantly complicates parsing.{{efn|Introducing a new operator changes the [[lexical specification]] of the language, which changes the [[lexical analysis]]. The arity and precedence of the operator is then part of the phrase syntax of the language, which changes the phrase-level analysis. For example, adding an operator <code>@</code> requires lexing and tokenizing this character, and the phrase structure (syntax tree) depends on the arity and precedence of this operator.}} Many languages only allow operators to be used for built-in types, but others allow existing operators to be used for user-defined types; this is known as [[operator overloading]]. Some languages allow new operators to be defined, however, either at compile time or at run time. This may involve meta-programming (specifying the operators in a separate language), or within the language itself. Definition of new operators, particularly runtime definition, often makes correct [[static analysis]] of programs impossible, since the syntax of the language may be Turing-complete, so even constructing the syntax tree may require solving the halting problem, which is impossible. This occurs for [[Perl]], for example, and some dialects of [[Lisp (programming language)|Lisp]].
Some languages support user-defined [[operator overloading|overloading]] (such as [[C++]] and [[Fortran]]). An operator, defined by the language, can be [[function overloading|overloaded]] to behave differently based on the type of input.
 
Some languages (e.g. C, C++ and [[PHP]]) define a fixed set of operators, while others (e.g. [[Prolog]],<ref>{{Cite web|url=https://www.swi-prolog.org/pldoc/man?predicate=op/3|title=SWI-Prolog -- op/3|website=www.swi-prolog.org}}</ref> [[Seed7]],<ref>{{Cite web|url=https://seed7.sourceforge.net/examples/operator.htm|title=Declare an operator|website=seed7.sourceforge.net}}</ref> [[F Sharp (programming language)|F#]], [[OCaml]], [[Haskell]]) allow for user-defined operators. Some programming languages restrict operator symbols to special characters like {{mono|1='''[[Addition|+]]'''}} or {{mono|1='''[[Assignment (computer science)|:=]]'''}} while others allow names like <code>[[Integer_division#Division_of_integers|div]]</code> (e.g. [[Pascal (programming language)|Pascal]]), and even arbitrary names (e.g. [[Fortran]] where an upto 31 character long operator name is enclosed between dots<ref name="IntelFortran">{{cite web |title=Defined Operations |url=https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-0/defined-operations.html |publisher=Intel |access-date=6 May 2025}}</ref>).
== Examples ==
{{category see also|Operators (programming)}}
Common examples that differ from functions syntactically are [[relational operator]]s, e.g. "&gt;" for "[[greater than]]", with names often outside the language's set of [[identifier (computer science)|identifiers]] for functions, and called with a syntax different from the language's syntax for calling functions. As a function, "greater than" would generally be named by an identifier, such as <code>gt</code> or <code>greater_than</code> and called as a function, as <code>gt(x, y)</code>. Instead, the operation uses the special character <code>&gt;</code> (which is tokenized separately during [[lexical analysis]]), and infix notation, as <code>x &gt; y</code>.
 
Most languages do not support user-defined operators since the feature significantly complicates parsing. Introducing a new operator changes the arity and precedence [[lexical specification]] of the language, which affects phrase-level [[lexical analysis]]. Custom operators, particularly via runtime definition, often make correct [[static analysis]] of a program impossible, since the syntax of the language may be Turing-complete, so even constructing the syntax tree may require solving the halting problem, which is impossible. This occurs for [[Perl]], for example, and some dialects of [[Lisp (programming language)|Lisp]].
Common examples that differ semantically (by argument passing mode) are Boolean operations, which frequently feature [[short-circuit evaluation]]: e.g. a short-circuiting conjunction (X AND Y) that only evaluates later arguments if earlier ones are not false, in a language with strict call-by-value functions. This behaves instead similarly to if/then/else.
 
If a language does allow for defining new operators, the mechanics of doing so may involve meta-programming {{endash}} specifying the operator in a separate language.
Less common operators include:
* [[Comma operator]]: <code>e, f</code>
* [[Dereference operator]]: <code>*p</code> and address-of operator: <code>&amp;x</code>
* [[?:]] or ternary operator: <code>number = spell_out_numbers ? "forty-two" : 42</code>
** [[Elvis operator]]: <code>x ?: y</code>
* [[Null coalescing operator]]: <code>x ?? y</code>
* [[Spaceship operator]] (for [[three-way comparison]]): <code>x &lt;=&gt; y</code>
* {{anchor|Compound operator|Fused operation}} [[Compound operator]]s<!-- This should probably become a separate article at a later stage --> combining two or more [[atomic operation]]s into one to simplify [[compound expression|expression]]s, ease compiler optimizations depending on the underlying hardware implementation, or improve performance for speed or size. An example are the set of [[compound assignment operator]]s (aka augmented assignments) in C/C++: <code>+=</code>, <code>-=</code>, <code>*=</code>, <code>/=</code>, <code>%=</code>, <code><<=</code>, <code>>>=</code>, <code>&=</code>, <code>^=</code>, <code>|=</code> Similarly, some [[digital signal processor]]s provide special [[opcode]]s for [[fused operation]]s<!-- This should probably become a separate article at a later stage, possibly combined with the similar topic on compound operations --> like [[multiply–accumulate]] (MAC/MAD) or [[fused multiply–add]] (FMA) and some high-performance software libraries support functions like [[cis (mathematics)|{{math|1=cis ''x'' = cos ''x'' + ''i'' sin ''x''}}]] to boost processing speed or reduce code size.
 
== OperatorOperand overloadingcoercion ==
{{further|Type conversion}}
{{main|Operator overloading}}
Some languages implicitly convert (aka [[Type conversion#Implicit type conversion|coerce]]) operands to be compatible with each other. For example, [[Perl]] coercion rules cause <code>12 + "3.14"</code> to evaluate to <code>15.14</code>. The string literal <code>"3.14"</code> is converted to the numeric value 3.14 before addition is applied. Further, <code>3.14</code> is treated as floating point so the result is floating point even though <code>12</code> is an integer literal. [[JavaScript]] follows different rules so that the same expression evaluates to <code>"123.14"</code> since <code>12</code> is converted to a string which is then concatenated with the second operand.
 
In general, a programmer must be aware of the specific rules regarding operand coercion in order to avoid unexpected and incorrect behavior.
In some programming languages an operator may be ''ad hoc polymorphic'', that is, have definitions for more than one kind of data, (such as in [[Java (programming language)|Java]] where the {{code|+}} operator is used both for the addition of numbers and for the concatenation of strings). Such an operator is said to be ''overloaded''. In languages that support operator overloading by the programmer (such as [[C++]]) but have a limited set of operators, operator overloading is often used to define customized uses for operators.
 
== Examples ==
In the example {{code|IF ORDER_DATE > "12/31/2011" AND ORDER_DATE < "01/01/2013" THEN CONTINUE ELSE STOP|basic}}, the operators are: {{code|>}} (greater than), {{code|AND}} and {{code|<}} (less than).
{{category see also|Operators (programming)}}
 
;Mathematical operators
== Operand coercion ==
* [[Arithmetic]]: such as addition, <code>a {{red|+}} b</code>
{{further|Type conversion}}
* [[Relational operator|Relational]]: such as [[Greater-than sign|greater than]], <code>a {{red|&gt;}} b</code>
Some languages also allow for the operands of an operator to be implicitly converted, or ''[[Type conversion#Implicit type conversion|coerced]]'', to suitable data types for the operation to occur. For example, in [[Perl]] coercion rules lead into <code>12 + "3.14"</code> producing the result of <code>15.14</code>. The text <code>"3.14"</code> is converted to the number 3.14 before addition can take place. Further, <code>12</code> is an integer and <code>3.14</code> is either a floating or fixed-point number (a number that has a decimal place in it) so the integer is then converted to a floating point or fixed-point number respectively.
* [[Mathematical logic|Logic]]: such as <code>a {{red|AND}} b</code> or <code>a {{red|&amp;&amp;}} b</code>
* [[Assignment (computer science)|Assignment]]: such as <code>a {{red|&equals;}} b</code> or <code>a {{red|:&equals;}} b</code>
* [[Three-way comparison]] (aka spaceship): <code>x {{red|&lt;&equals;&gt;}} y</code>
 
;Program structure operators
* [[Record (computer science)|Record]] or [[Object (computer science)|object]] [[Field (computer science)|field]] access: such as <code>a{{red|.}}b</code>
* [[scope resolution operator|Scope resolution]]: such as <code>a{{red|::}}b</code> or <code>a{{red|.}}b</code>
 
;Conditional operators
* [[Ternary conditional operator|Ternary conditional]]: <code>condition {{red|?}} a {{red|:}} b</code>
* [[Elvis operator|Elvis]]: <code>x {{red|?:}} y</code>
* [[Null coalescing operator|Null coalesing]]: <code>x {{red|??}} y</code>
 
;Notable C and C++ operators
[[JavaScript]] follows opposite rules—finding the same expression above, it will convert the integer <code>12</code> into a string <code>"12"</code>, then concatenate the two operands to form <code>"123.14"</code>.
* Address-of operator: <code>{{red|&amp;}}x</code>
* [[Dereference operator|Dereference]]: <code>{{red|*}}p</code>
* [[Comma operator|Comma]]: <code>e{{red|,}} f</code>
 
{{anchor|Compound operator|Fused operation}}
In the presence of coercions in a language, the programmer must be aware of the specific rules regarding operand types and the operation result type to avoid subtle programming mistakes.
;Compound operators
* [[compound assignment operator|Compound assignment]] (aka augmented assignment) in C/C++: <code>+=</code>, <code>-=</code>, <code>*=</code>, <code>/=</code>, <code>%=</code>, <code><<=</code>, <code>>>=</code>, <code>&=</code>, <code>^=</code>, <code>|=</code>
* [[fused operation|Fused]]: such as [[cis (mathematics)|{{math|1=cis ''x'' = cos ''x'' + ''i'' sin ''x''}}]]
 
== Operator features in programming languages ==
Line 68 ⟶ 94:
!Symbolic operators
!Alphanumeric operators
! {{verth|Prefix}}
! {{verth|Infix}}
! {{verth|Postfix}}
! {{verth|Precedence}}
! {{verth|Associativity}}
! {{verth|Overloading}}
! {{verth|ProgrammerUser-defined<br/>overloading}}
! {{verth|ProgrammerUser-defined<br/>operator symbols}}
|-
| [[ALGOL 68]] <small>each symbolic operator has an alphanumeric equivalent and some a non-[[ASCII]] equivalent</small>
| {{monocode|1=+* ** * / % %* %× - + &lt; &lt;= >= > = /= & -:= +:= *:= /:= %:= %*:= +=: :=: :/=:}}
('''non-ASCII):'''
{{monocode|1=¬ +× ⊥ ↑ ↓ ⌊ ⌈ × ÷ ÷× ÷* □ ≤ ≥ ≠ ∧ ∨ ×:= ÷:= ÷×:= ÷*:= %×:= :≠:}}
| {{monocode|not abs arg bin entier leng level odd repr round shorten i shl shr up down lwb upb lt le ge gt eq ne and or over mod elem minusab plusab timesab divab overab modab plusto is {{Not a typo|isnt}}}}
| {{Yes}}
| {{Yes}}
Line 92 ⟶ 118:
|-
| [[APL (programming language)|APL]]
| {{monocode|1=+ - × ÷ ⌈ ⌊ * ⍟ <nowiki>|</nowiki> ! ○ ~ ∨ ∧ ⍱ ⍲ &lt; ≤ = ≥ > ≠ . @ ≡ ≢ ⍴ , ⍪ ⍳ ↑ ↓ ? ⍒ ⍋ ⍉ ⌽ ⊖ ∊ ⊥ ⊤ ⍎ ⍕ ⌹ ⊂ ⊃ ∪ ∩ ⍷ ⌷ ∘ → ← / ⌿ \ ⍀ ¨ ⍣ & ⍨ ⌶ ⊆ ⊣ ⊢ ⍠ ⍤ ⌸ ⌺ ⍸}}
| (alphanumeric symbols need arequires ⎕ prefix)
| {{Yes}} <small>(first-order functions only)</small>
| {{Yes}}
Line 104 ⟶ 130:
|-
|[[B (programming language)|B]]
|{{monocode|1=() [] ! ~ ++ -- + - * & / % << >> < <= > >= == != ^ <nowiki>|</nowiki> [[?:]] = =+ =- =* =/ =% =& =^ =<nowiki>|</nowiki>}}<ref>{{Cite web |title=A TUTORIAL INTRODUCTION TO THE LANGUAGE B |url=https://www.bell-labs.com/usr/dmr/www/btut.html |access-date=2024-08-03 |archive-date=2017-04-03 |archive-url=https://web.archive.org/web/20170403063756/https://www.bell-labs.com/usr/dmr/www/btut.html |url-status=dead }}</ref>
|
|{{Yes}}
Line 116 ⟶ 142:
|-
| [[C (programming language)|C]]
| {{monocode|1=() [] -> . ! ~ ++ -- + - * & / % << >> < <= > >= == != ^ <nowiki>|</nowiki> && <nowiki>||</nowiki> [[?:]] = += -= *= /= %= &= ^= |= <<= >>=}}
| {{mono|<code>[[sizeof]]}}</code>
| {{Yes}}
| {{Yes}}
Line 129 ⟶ 155:
| [[C++]]
| (same as C)
| (same as C plus) {{mono|<code>[[typeid]] [[new (C++)|new]] [[delete (C++)|delete]] [[Exception handling|throw]] [[decltype]] [[static_cast]] [[dynamic cast]] [[reinterpret_cast]] [[const_cast]]}}</code>
| {{Yes}}
| {{Yes}}
Line 140 ⟶ 166:
|-
| [[C sharp (programming language)|C#]]
| (same as C plus) {{mono|<code>[[?.]] ?[] [[Null coalescing operator|??]] <nowiki>??=</nowiki>}}</code>
| {{mono|1=<code>[[sizeof]] nameof new stackalloc await [[Exception handling|throw]] checked unchecked is as delegate default true false}}</code> <br /> ('''[[LINQ]]):''' {{mono|1=<code>from select where group...by group...by...into join...in...on...equals join...in...on...equals...into orderby orderby...descending}}</code> <br /> ('''[[Roslyn (compiler)|Roslyn]]-only):''' {{mono|1=<code>__makeref __refvalue __reftype}}</code>
| {{Yes}}
| {{Yes}}
Line 153 ⟶ 179:
| [[Java (programming language)|Java]]
| (same as C)
| <code>[[Java syntax#Instantiation|new]] [[Exception handling|throw]] [[instanceof]]</code>
| {{Yes}}
| {{Yes}}
Line 164 ⟶ 190:
|-
| [[Eiffel (programming language)|Eiffel]]
| {{mono|1=<code>[] + - * / // = /= }}</code>
| {{mono|1=<code>not and or implies "and then" "or else" }}</code>
| {{Yes}}
| {{Yes}}
Line 176 ⟶ 202:
|-
| [[Haskell]]
| {{mono|1=<code>+ - * / ^ ^^ ** == /= > < >= <= && <nowiki>||</nowiki> >>= >> $ $! . ++ !! :}}</code> <small>Many(and moremany in common librariesmore)</small>
| (function name must be in backticks)
| {{Yes}}
Line 185 ⟶ 211:
| colspan="2" {{Yes}}, using [[Type class]]es
| {{Yes}}
|-
| [[MultiValue|mvBasic Databasic/Unibasic]]
|<code>+ - * / ^ ** : = ! & [] += -= := # < > <= >= <> >< =< #> => #< </code>
|<code>AND OR NOT EQ NE LT GT LE GE MATCH ADDS() ANDS() CATS() DIVS() EQS() GES() GTS() IFS()</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
|-
| [[Pascal (programming language)|Pascal]]
| {{mono|1=<code>* / + - = < > <> <= >= :=}}</code>
| <code>[[Negation#Programming|not]] [[Integer division#Division of integers|div]] [[Modulo operation|mod]] [[Logical conjunction|and]] [[Logical disjunction|or]] in</code>
| {{Yes}}
| {{Yes}}
Line 199 ⟶ 237:
|-
| [[Perl]]
| {{mono|1=<code>-> ++ -- ** ! ~ \ + - . =~ !~ * / % < > <= >= == != <=> ~~ & <nowiki>|</nowiki> ^ &amp;&amp; <nowiki>||</nowiki> ' ''&apos;&apos; {{Not a typo| // .. ... ?: {{=}} +{{=}} -{{=}} *{{=}} , {{=>}} >}} </code>
| {{mono|1=<code>print sort chmod chdir rand and or not xor lt gt le ge eq ne cmp x }}</code>
| {{Yes}}
| {{Yes}}
Line 211 ⟶ 249:
|-
| [[PHP]]
| {{mono|1=<code>[] ** ++ -- ~ @!<ref>{{Cite web|url=https://php.net/manual/en/language.operators.errorcontrol.php|title=PHP: Error Control Operators - Manual|website=php.net}}</ref> * / % + - . << >> < <= > >= == != === !== <> [[Spaceship operator|<=>]] & ^ <nowiki>|</nowiki> && <nowiki>||</nowiki> [[Null coalescing operator|??]] [[?:]] = += -= *= **= /= .= %= &= <nowiki>|=</nowiki> ^= <<= >>= }}</code>
| {{mono|1=<code>clone new unset print echo isset [[instanceof]] [[Logical conjunction|and]] [[Logical disjunction|or]] [[xor]]}}</code>
| {{Yes}}
| {{Yes}}
Line 223 ⟶ 261:
|-
| [[PL/I]]
| {{mono|1=<code>( ) -> + - * / ** > ¬> >= = ¬= <= < ¬< ¬ <nowiki>&</nowiki> <nowiki>|</nowiki> <nowiki>||</nowiki>}}</code>
|
| {{Yes}}
Line 235 ⟶ 273:
|-
| [[Prolog]]
| {{mono|1=<code>:- ?- ; , . =.. = \= < =< >= > == \== - + / *}}</code>
| {{mono|1=<code>spy nospy not is mod}}</code>
| {{Yes}}
| {{Yes}}
Line 247 ⟶ 285:
|-
| [[Raku (programming language)|Raku]]
| {{mono|1=<code>++ -- ** ! ~ ~~ * / + - . < > <= >= == != <=> & <nowiki>|</nowiki> ^ &amp;&amp; <nowiki>||</nowiki> //}}</code> <ref>{{Cite web|url=https://docs.perl6.org/language/operators|title=Operators|website=docs.perl6.org}}</ref>
| {{mono|1=<code>print sort chmod chdir rand and or not xor lt gt le ge eq ne leg cmp x xx}}</code>
| {{Yes}}
| {{Yes}}
Line 259 ⟶ 297:
|-
| [[Seed7]]
| {{mono|1=<code>{} [] -> ** ! + - * / << >> & >< <nowiki>|</nowiki> = <> > >= < <= <& := +:= -:= *:= /:= <<:= >>:= &:= @:=}}</code>
| {{mono|1=<code>conv varConv parse [[Complex conjugate|conj]] [[Integer division#Division of integers|div]] [[Remainder|rem]] [[Modulo operation|mdiv mod]] times mult in [[Negation#Programming|not]] [[Logical conjunction|and]] [[Logical disjunction|or]] digits lpad rpad lpad0}}</code>
| {{Yes}}
| {{Yes}}
Line 271 ⟶ 309:
|-
| [[Smalltalk]]
| (yes - Upup to two characters<ref name="BinaryMessages">{{cite web|first=Adele|last=Goldberg|url=http://stephane.ducasse.free.fr/FreeBooks/BlueBook/Bluebook.pdf|title=Smalltalk-80: The Language and its Implementation, p. 27, ISBN 0-201-11371-6}}</ref>)
| (alphanumeric symbols need a colon suffix)
| {{No}}
Line 283 ⟶ 321:
|-
| [[Swift (programming language)|Swift]]
| (any Unicode symbol string except) {{mono|1=<code>.}}</code> (including) {{mono|1=<code>! ~ + - * / % =+ =- =* =/ =% &+ &- &* =&+ =&- =&* && <nowiki>||</nowiki> << >> & <nowiki>|</nowiki> ^ == != < <= > >= ?? ... ..<}} (in standard library)</code>
| {{mono|1=<code>is as as?}}</code>
| {{Yes}}
| {{Yes}}
Line 295 ⟶ 333:
|-
| [[Visual Basic .NET]]
| rowspan="2" | {{mono|1=<code>() . ! ?() ?. ?! + - * / \ & << >> < <= > >= ^ <> = += -= *= /= \= &= ^= <<= >>=}}</code>
| {{mono|1=<code>New Await Mod Like Is IsNot Not And AndAlso Or OrElse Xor If(...,...) If(...,...,...) GetXmlNamespace(...) GetType(...) NameOf(...) TypeOf...Is TypeOf...IsNot DirectCast(...,...) TryCast(...,...) CType(...,...) CBool(...) CByte(...) CChar(...) CDate(...) CDec(...) CDbl(...) CInt(...) CLng(...) CObj(...) CSByte(...) CShort(...) CSng(...) CStr(...) CUInt(...) CULng(...) CUShort(...)}}</code> <br /> ('''[[LINQ]]):''' {{mono|1=<code>From Aggregate...Into Select Distinct Where {{nowrap|<Order By>...[Ascending<nowiki>|</nowiki>Descending]}} Take {{nowrap|<Take While>}} Skip {{nowrap|<Skip While>}} Let Group...By...Into Join...On <Group Join...On...Into>}}</code>
| {{Yes}}
| {{Yes}}
Line 309 ⟶ 347:
 
== See also ==
* [[RelationalOperators operatorin C and C++]]
 
== Notes ==
{{notelist}}
 
== References ==