Strings Mathematics [BitXXX e.g. BitAnd, XXXDiv e.g. TrueDiv] Operators and Symbols General (Control Flow/Debugging) Dates Objects [Range.New/Range.NewUntil] New Features Timelines Documentation Links Sections: Introduction By Role By Symbol Testing Operator Precedence Summary: Operators Across Multiple Languages Operators and Symbols Listed in: The C Programming Language (1978) The Universal Function Library Project: Details Inventing Operators Multi-Line Comments Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details.
Note: most of these symbols are operators, but some are not, e.g. comment symbols. Operators are typically comprised of characters from what I call, the 'classic 32': !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ Start with ASCII chars 33-126 (94 chars), remove A-Za-z0-9 (62 chars), that gives 32 chars. Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details.
UFL: OpSpreadCall/OpSpreadReceive [spread operator (splat operator)][in a function call: 'spread' an array as multiple separate arguments][in a function definition: receive the trailing arguments (0 or more) as an array] AutoHotkey: */* C++: [none]/... C#: ../params Crystal: */* Excel: [none]/[none] Excel VBA: [none]/ParamArray Go: .../... Java: [none]/... JavaScript: .../... Kotlin: */vararg PHP: .../... Python: */* R: [none]/... Ruby: */* Rust: [none]/[none] Scala: */* SQL (MySQL): [none]/[none] SQL (PostgreSQL): [none]/VARIADIC SQL (SQLite): [none]/[none] Swift: [none]/... UFL: OpSpreadCallDemo [spread operator: for variadic function calls] AutoHotkey: * [e.g. MyFunc(oArray*)] C++: [none] C#: .. [e.g. MyFunc(..oArray)] [note: 2 dots (not 3)] [WARNING: .. doesn't work universally in function calls] Crystal: * [e.g. MyFunc(*oTuple)] [note: works on tuples but not arrays] Excel: [none] Excel VBA: [none] Go: ... [e.g. MyFunc(oArray...)] Java: [none] JavaScript: ... [e.g. MyFunc(...oArray)] [note: spread syntax] [also: MyFunc.apply(null, oArray)] Kotlin: * [e.g. MyFunc(*oArray)] PHP: ... [e.g. MyFunc(...$oArray)] Python: * [e.g. MyFunc(*oArray)] [note: splat] R: [none] [can use: do.call(oFunc, as.list(oVec))] Ruby: * [e.g. MyFunc(*oArray)] Rust: [none] Scala: * [e.g. MyFunc(oArray*)] SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: [none] UFL: OpSpreadReceiveDemo [spread operator: for variadic function definitions][see also: FuncDemoSum] AutoHotkey: * [e.g. MySum(oParams*)] C++: ... [note: fold expressions] [also: macros: ... and __VA_ARGS__] [also: va_list/va_start/va_arg/va_end (WARNING: this approach requires that the value of a param, e.g. the first param, indicate how many params were passed)] C#: params [e.g. public static int MySum(params int[] oParams)] Crystal: * [e.g. def mySum(*oParams)] [note: works on tuples but not arrays] Excel: [none] Excel VBA: ParamArray [e.g. Function MySum(ParamArray oParams())] Go: ... [e.g. func MySum(oParams ...int) int {] Java: ... [e.g. varargs syntax: static int MySum(int... oParams)] [WARNING: 'varargs' (with 's') is name, '...' is syntax] JavaScript: ... [e.g. function MySum(...oParams)] [also: oParams = Array.prototype.slice.call(arguments)] Kotlin: vararg [e.g. fun MySum(vararg oParams: Int) : Int] [WARNING: 'vararg' (no 's') is syntax and name] PHP: ... [e.g. function MySum(...$oParams)] Python: * [e.g. def MySum(*oParams):] R: ... [e.g. MySum = function(...)] [afterwards: oParams = list(...)] Ruby: * [e.g. MySum(*oParams)] Rust: [none] Scala: * [e.g. def MySum(oParams: Int*) : Int =] SQL (MySQL): [none] SQL (PostgreSQL): VARIADIC [e.g. CREATE FUNCTION MySum(VARIADIC oArray int[]) RETURNS int AS] SQL (SQLite): [none] Swift: ... [e.g. func MySum(_ oParams: Int...) -> Int] [note: ... is also used for closed ranges] UFL: OpTern [ternary operator]['c ? x : y' is preferable since it's clear/concise/common, else use alternative symbols like Raku ('c ?? x !! y')][a ternary function (e.g. 'Tern') is a lesser option since it can't do short-circuit Boolean evaluation][note: state if bool/parentheses needed][see also: IsTruthy] AutoHotkey: c ? x : y C++: c ? x : y C#: c ? x : y [note: c must be a bool] Crystal: c ? x : y [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: [none] [can use: IF(c,x,y)] [note: c must be a bool or numeric] [WARNING: evaluates both branches] Excel VBA: [none] [can use: IIf(c, x, y)] [note: c must be a bool or numeric] [WARNING: evaluates both branches] [note: immediate if (or inline if)] Go: [none] [can use (return int): vRet := map[bool]int{true: 1, false: 0}[vBool]] [can use (return string): vRet := map[bool]string{true: "true", false: "false"}[vBool]] [MAJOR WARNING: Go lacks any form of ternary operator, an if/else statement is a 5-liner, or a 6-liner if also declaring a variable] Java: c ? x : y [note: c must be a bool] JavaScript: c ? x : y Kotlin: if (c) x else y [WARNING: unusual operators] [note: c must be a bool] [note: can be used in expressions] [note: parentheses *are* needed] PHP: c ? x : y [note: can't chain ternary operator, unless use parentheses, e.g. a ? b : (c ? d : e)] Python: x if c else y [MAJOR WARNING: unusual operators, and operand order] [note: can be used in expressions] [note (a custom ternary function): Tern = lambda vBool, oFuncT, oFuncF : (oFuncT() if callable(oFuncT) else oFuncT) if vBool else (oFuncF() if callable(oFuncF) else oFuncF)] [e.g. Tern(vNum >= 0, lambda : print("is positive/zero"), lambda : print("is negative"))] [e.g. vSignBit = Tern(vNum >= 0, 0, 1)] [also: vRet = {True:1, False:0}[vBool]] R: if (c) x else y [also: ifelse(c, x, y)] [also: `if`(c, x, y)] Ruby: c ? x : y [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: if c {x} else {y} [WARNING: unusual operators] [note: c must be a bool] [note: can be used in expressions] [note: curly braces are needed] Scala: if(c) x else y [WARNING: unusual operators] [note: c must be a bool] [note: can be used in expressions] [note: parentheses *are* needed] SQL (MySQL): [none] [can use: if(c, x, y)] [also: (CASE WHEN c THEN x ELSE y END)] [MAJOR WARNING: in MySQL, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] SQL (PostgreSQL): [none] [can use: (CASE WHEN c THEN x ELSE y END)] [note: c must be a bool] SQL (SQLite): [none] [can use: iif(c, x, y)] [also: if(c, x, y)] [also: (CASE WHEN c THEN x ELSE y END)] [MAJOR WARNING: in SQLite, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] Swift: c ? x : y [note: c must be a bool] UFL: OpShortTern [short-ternary operator][x ?: y][equivalent to x ? x : y][e.g. (x != 0) ? x : y][e.g. (x != "") ? x : y][if x is truthy, return x, else y][a 'falsy-coalescing operator': if x is non-falsy, return x, else y][note: can be chained to return the first truthy value, or last falsy value][see also: IsTruthy/Array.FindOrDefaultDemo/OpNullCoalescing] AutoHotkey: || [note: AHK v2 onwards] [e.g. a || b || c] C++: [none] [can use: int oArray[] = {a, b, c}; auto oIter = std::find_if(std::begin(oArray), std::end(oArray), [](int v) {return v!=0;}); auto vValue = (oIter != std::end(oArray)) ? *oIter : 0;] [also: a?a : b?b : c] [requires (find_if): #include <algorithm>] C#: [none] [can use: Array.Find((int[])[a, b, c], v=>v!=0)] [WARNING: Find() returns the array's/list's default value if no match (e.g. 0 for ints, null for strings)] [also: (a!=0) ? a : (b!=0) ? b : c] Crystal: || [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [e.g. (but treats 0 as truthy): a || b || c] [can use: [a, b, c].find(0){|v|v!=0}] [also: (a!=0) ? a : (b!=0) ? b : c] Excel: [none] Excel VBA: [none] Go: [none] [can use: cmp.Or(a, b, c)] [requires: import "cmp"] Java: [none] [can use: Arrays.stream(new int[]{a, b, c}).filter(v->v!=0).findFirst().orElse(0)] [also: (a!=0) ? a : (b!=0) ? b : c] [requires (Arrays): import java.util.*] JavaScript: || [e.g. a || b || c] Kotlin: [none] [can use: arrayOf(a, b, c).find{it!=0} ?: 0] [also: if (a!=0) a else if (b!=0) b else c] PHP: ?: [e.g. $a ?: $b ?: $c] Python: or [e.g. a or b or c] R: [none] [can use: if (vVar) vVar else vDefault] [also: `if`(vVar, vVar, vDefault)] [note: an error occurs if NULL or a string is tested for truthiness] [also: Find(\(v) v!=0, c(a, b, c), nomatch=0)] Ruby: || [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [e.g. (but treats 0 as truthy): a || b || c] [can use: [a, b, c].find(->{0}){|v|v!=0}] [also: (a!=0) ? a : (b!=0) ? b : c] Rust: [none] [can use: [a, b, c].into_iter().find(|v|*v!=0).unwrap_or(0)] Scala: [none] [can use: Array(a, b, c).find(_!=0).getOrElse(0)] [also: if(a!=0) a else if(b!=0) b else c] SQL (MySQL): [none] [can use: if(a, a, b)] [also: (CASE WHEN a THEN a WHEN b THEN b ELSE c END)] SQL (PostgreSQL): [none] [can use: (CASE WHEN a!=0 THEN a WHEN b!=0 THEN b ELSE c END)] SQL (SQLite): [none] [can use: iif(a, a, b, b, c)] [also: if(a, a, b, b, c)] [also: (CASE WHEN a THEN a WHEN b THEN b ELSE c END)] Swift: [none] [can use: [a, b, c].first{$0 != 0} ?? 0] [also: (a != 0) ? a : (b != 0) ? b : c] UFL: OpNullCoalescing [or OpNullCoalesce][null-coalescing operator][x ?? y][equivalent to (x != null) ? x : y][if x is non-null, return x, else y][workaround: in some situations OpShortTern will work, e.g. (non-empty) objects are truthy, nulls are falsy][see also: Optional.UnwrapOrDefault/Array.Find/Array.GetOrDefault/OpShortTern] AutoHotkey: [none] C++: [none] C#: ?? Crystal: [none] [can use: [vVar,vDefault].find{|v|v!=nil}] [also: (vVar != nil) ? vVar : vDefault] [also (but with a confusing order): vVar.nil? ? vDefault : vVar] Excel: [none] [can use: IFERROR(A1,vDefault)] Excel VBA: [none] Go: [none] Java: [none] [can use: Optional.ofNullable(vVar).orElse(vDefault)] [also: oOpt.orElse(vDefault)] JavaScript: ?? [note: nullish-coalescing operator] [note: 'nullish': null or undefined] Kotlin: ?: [WARNING: in Kotlin, '?:' is a null-coalescing operator, not a short-ternary operator: e.g. '0 ?: 123' returns 0, since 0 is non-null] PHP: ?? Python: [none] [can use: next((v for v in [vVar] if v is not None), vDefault)] [also: vVar if (vVar is not None) else vDefault] R: [none] [can use (NA-coalescing): na.omit(c(vVar,vDefault))[1]] [also: if (is.null(vVar)) vVar else vDefault] [also: `if`(is.null(vVar), vVar, vDefault)] Ruby: [none] [can use: [vVar,vDefault].find{|v|v!=nil}] [also: (vVar != nil) ? vVar : vDefault] [also (but with a confusing order): vVar.nil? ? vDefault : vVar] Rust: [none] [can use (option object): oOpt.unwrap_or(vDefault)] [also: map_or/map_or_else/unwrap_or_else] Scala: [none] [can use (unwraps value): Option(vVar).getOrElse(vDefault)] [also (returns an option): Option(vVar).orElse(Option(vDefault))] SQL (MySQL): [none] [can use: coalesce(MyCol, MyDefault)] [note: coalesce() accepts 2 or more parameters, it returns the first non-null value, else null] [WARNING: ifnull is a confusingly-named alias for the 2-param version of coalesce] SQL (PostgreSQL): [none] [can use: coalesce(MyCol, MyDefault)] [note: coalesce() accepts 2 or more parameters, it returns the first non-null value, else null] SQL (SQLite): [none] [can use: coalesce(MyCol, MyDefault)] [note: coalesce() accepts 2 or more parameters, it returns the first non-null value, else null] [WARNING: ifnull is a confusingly-named alias for the 2-param version of coalesce] Swift: ?? [note: nil-coalescing operator] [note: Swift uses nils rather than nulls] UFL: SymSep [statement separator][for multiple statements on 1 line] AutoHotkey: , C++: ; [note: statements must end with ;] C#: ; [note: statements must end with ;] Crystal: ; Excel: [none] Excel VBA: : [note: colon (not semicolon)] Go: ; [note: the Go Playground auto-formats these away (replacing multi-statement one-liners with multiple lines)] Java: ; [note: statements must end with ;] JavaScript: ; Kotlin: ; PHP: ; [note: statements must end with ;] Python: ; R: ; Ruby: ; Rust: ; [note: statements must end with ; (except the last)] Scala: ; SQL (MySQL): ; [note: statements must end with ; (except the last)] SQL (PostgreSQL): ; [note: statements must end with ; (except the last)] SQL (SQLite): ; [note: statements must end with ; (except the last)] Swift: ; UFL: SymEnd [statement terminator][whether lines must end with a char/symbol (e.g. semicolon)] AutoHotkey: [none] C++: ; C#: ; Crystal: [none] Excel: [none] Excel VBA: [none] Go: [none] Java: ; JavaScript: [none] [note: though it is common to end lines with ;] Kotlin: [none] PHP: ; Python: [none] R: [none] Ruby: [none] Rust: ; [note: the last statement does not require a trailing semicolon] Scala: [none] SQL (MySQL): ; [note: the last statement does not require a trailing semicolon] SQL (PostgreSQL): ; [note: the last statement does not require a trailing semicolon] SQL (SQLite): ; [note: the last statement does not require a trailing semicolon] Swift: [none] UFL: SymStringLiteral [characters for assigning string literals][see also: SymInterpolateDemo/Format/SymCharApos/JsonArrayDemo/JsonObjectDemo] AutoHotkey: " [also (AHK v2 onwards): '] C++: " [note: ' is used for chars] C#: " [note: ' is used for chars] Crystal: " [note: ' is used for chars] Excel: " Excel VBA: " [WARNING: ' is used for comments] Go: " [note: ' is used for chars] Java: " [note: ' is used for chars] JavaScript: " [also: '] Kotlin: " [note: ' is used for chars] PHP: " [also: '] Python: " [also: '] R: " [also: '] Ruby: " [also: '] Rust: " [note: ' is used for chars] Scala: " [note: ' is used for chars] SQL (MySQL): ' [also: "] [WARNING: ' is used for strings] [note: ` is used for identifiers (e.g. column names)] SQL (PostgreSQL): ' [WARNING: ' is used for strings] [WARNING: " is used for identifiers (e.g. column names)] SQL (SQLite): ' [WARNING: ' is used for strings] [WARNING: " is used for identifiers (e.g. column names)] Swift: " UFL: SymCharLiteral [characters for assigning character literals][see also: SymCharApos] AutoHotkey: [none] C++: ' [note: ' is also a numeric literal separator] C#: ' Crystal: ' Excel: [none] Excel VBA: [none] [WARNING: ' is used for comments] Go: ' Java: ' JavaScript: [none] Kotlin: ' PHP: [none] Python: [none] R: [none] Ruby: [none] Rust: ' Scala: ' SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: [none] UFL: SymEscape [string escape character][individual characters by frequency: nrt\'" abfv0 es$;?][see also: IntToStrCharEscapeDemo/StringNewDemoAscii/StrMultiLineDemo] AutoHotkey: ` [`a `b `f `n `r `s `t `v `` `' `" `;] [note: `; only required if ; is before space/tab] [note: AHK v1 used dual quoting for "] [also: A_Space A_Tab] C++: \ [\a \b \f \n \r \t \v \' \" \\ \?] [also (with further chars): \0 \N \u \U \x] [also: \c] [WARNING: \x stops at the first non-hex digit (workaround: use string literal concatenation, to mark the end of the sequence)] C#: \ [\a \b \e \f \n \r \t \v \' \" \\ \0] [also (with further chars): \u \U \x] [WARNING: \x can handle 1-4 hex digits, but it is safer to always use 4 (to avoid later chars being accidentally interpreted as part of the sequence)] Crystal: \ [\a \b \e \f \n \r \t \v \' \" \\] [also (with further chars): \0 \1 \2 \3 \u \x] Excel: [none] [note: uses dual quoting: e.g. "a""b"] Excel VBA: [none] [note: uses dual quoting: e.g. "a""b"] [also: vbBack vbCr vbCrLf vbFormFeed vbLf vbNullChar vbTab vbVerticalTab] Go: \ [\a \b \f \n \r \t \v \' \" \\] [also (with further chars): \0 \1 \2 \3 \u \U \x] Java: \ [\b \f \n \r \t \' \" \\] [also (with further chars): \u] [MAJOR WARNING: Java replaces escaped chars, including in comments, before parsing the source code] [e.g. myvar = "\u0022" resolves to myvar = """, which is invalid, workaround: myvar = "\u005C\u0022" resolves to myvar = "\""] JavaScript: \ [\b \f \n \r \t \v \' \" \\ \0] [also (with further chars): \u \x] [note: \ followed by a line break gives a blank string] Kotlin: \ [\b \n \r \t \' \" \\ \$] [also (with further chars): \u] PHP: \ [\e \f \n \r \t \v \' \" \\ \$] [also (with further chars): \0 \1 \2 \3 \4 \5 \6 \7 \u \x] [note: for single quotes, \' and \\ are the only escape sequences] Python: \ [\b \f \n \r \t \' \" \\] [also (with further chars): \o \u \U \x] R: \ [\a \b \f \n \r \t \v \' \" \\] [also (with further chars): \0 \1 \2 \3 \4 \5 \6 \7 \u \U \x] Ruby: \ [\a \b \e \f \n \r \s \t \v \' \" \\] [also (with further chars): \0 \1 \2 \3 \4 \5 \6 \7 \C \c \M \u \x] [note: for single quotes, \' and \\ are the only escape sequences] Rust: \ [\n \r \t \' \" \\ \0] [also (with further chars): \u \x] Scala: \ [\b \f \n \r \t \' \" \\] [also (with further chars): \u] [MAJOR WARNING: Scala replaces escaped chars, including in comments, before parsing the source code] [deprecated (octals, with further chars): \0 \1 \2 \3] SQL (MySQL): \ [\b \n \r \t \Z \' \\ \0] [also: dual quoting: e.g. 'a''b'] [also (when pattern-matching): \% \_] [also (linefeed): '' with a literal linebreak in-between (press enter)] [e.g. equivalent to 'a\nb': 'a\nb'] SQL (PostgreSQL): \ [\b \f \n \r \t \' \\] [MAJOR WARNING: requires E/e prefix, e.g. E'\n', e.g. e'\n'] [also (with further chars): \0 \1 \2 \3 \4 \5 \6 \7 \u \U \x] [note: uses dual quoting: e.g. 'a''b'] [also (linefeed): '' with a literal linebreak in-between (press enter)] [e.g. equivalent to 'a\nb': E'a\nb'] [note: from PostgreSQL 9.1 onwards, 'standard_conforming_strings' is set to on, i.e. '\' is treated literally, use the 'E' prefix, e.g. E'\n', to use '\' as an escape char, to get/set this value: SELECT setting FROM pg_settings WHERE name = 'standard_conforming_strings'; SET standard_conforming_strings = on;] SQL (SQLite): [none] [note: uses dual quoting: e.g. 'a''b'] [also (linefeed): x'0a', char(10), '' with a literal linebreak in-between (press enter)] [e.g. equivalent to 'a\nb': 'a'||char(10)||'b'] Swift: \ [\n \r \t \' \" \\ \0] [also (with further chars): \u] UFL: SymInterpolateDemo [string interpolation][see also: Format/SymCharApos] AutoHotkey: [none] [can use: Format("Hello, {}!", name)] [also (single quotes, AHK v2 onwards): Format('Hello, {}!', name)] C++: [none] [can use: std::format("Hello, {}!", name)] [requires: #include <format>] [note: single quote is used for chars] C#: $"Hello, {name}!" [note: single quote is used for chars] Crystal: "Hello, #{name}!" [WARNING: # is a special character in string literals] [note: single quote is used for chars] Excel: [none] Excel VBA: [none] Go: [none] [can use: fmt.Sprintf("Hello, %v!", name)] [note: single quote is used for chars] Java: [none] [can use: String.format("Hello, %s!", name)] [note: single quote is used for chars] JavaScript: `Hello, ${name}!` Kotlin: "Hello, ${name}!" [also: "Hello, $name!"] [WARNING: $ is a special character in string literals] [note: single quote is used for chars] PHP: "Hello, {$name}!" [also: "Hello, $name!"] [WARNING: $ is a special character in string literals] [note: doesn't work with single quotes (although ' is used for strings)] [deprecated: "Hello, ${name}!"] Python: f"Hello, {name}!" [also (single quotes): f'Hello, {name}!'] R: [none] [can use: sprintf("Hello, %s!", name)] [also (single quotes): sprintf('Hello, %s!', name)] Ruby: "Hello, #{name}!" [WARNING: # is a special character in string literals] [note: doesn't work with single quotes (although ' is used for strings)] Rust: [none] [can use: format!("Hello, {name}!")] [note: single quote is used for chars] Scala: s"Hello, ${name}!" [also: s"Hello, $name!"] [note: single quote is used for chars] SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: "Hello, \(name)!" [note: doesn't work with single quotes (' is not used for strings or chars)] UFL: OpPow [power (exponent)][see also: Pow/OpPowUnaryAddDemo] AutoHotkey: ** C++: [none] [can use: pow(vNum1, vNum2)] C#: [none] [can use: Math.Pow(vNum1, vNum2)] Crystal: ** Excel: ^ Excel VBA: ^ Go: [none] [can use: math.Pow(vNum1, vNum2)] [requires: import "math"] Java: [none] [can use: Math.pow(vNum1, vNum2)] JavaScript: ** Kotlin: [none] [can use: Math.pow(vNum1, vNum2)] PHP: ** Python: ** R: ** [also: ^] Ruby: ** Rust: [none] [can use: vNum1.pow(vNum2)] Scala: [none] [can use: math.pow(vNum1, vNum2)] SQL (MySQL): [none] [can use: pow(MyNum1, MyNum2)] SQL (PostgreSQL): ^ [also: pow(MyNum1, MyNum2)] SQL (SQLite): [none] [can use: pow(MyNum1, MyNum2)] Swift: [none] [can use: pow(vNum1, vNum2)] [requires: import Foundation] UFL: SymComment [single-line comment] AutoHotkey: ; C++: // C#: // Crystal: # Excel: [none] [can use: N("my comment") returns 0, T(N("my comment")) returns "", LET()] Excel VBA: ' Go: // Java: // JavaScript: // Kotlin: // PHP: // [also: #] Python: # R: # Ruby: # Rust: // [WARNING: /// and //! are doc comments] Scala: // SQL (MySQL): -- [note: -- must be followed by space/tab/linefeed etc] [also: #] SQL (PostgreSQL): -- SQL (SQLite): -- Swift: // UFL: SymCommentMult [multi-line comments][note: also work as single-line comments] AutoHotkey: /* */ [WARNING: /* only works at the start of a line] [WARNING: */ only works at the start/end of a line] [note: these rules differ for AHK v1/v2] C++: /* */ C#: /* */ Crystal: [none] Excel: [none] Excel VBA: [none] Go: /* */ Java: /* */ JavaScript: /* */ Kotlin: /* */ PHP: /* */ Python: [none] [note: workaround: bare string literals can be used as comments: ''' """] R: [none] Ruby: =begin =end [WARNING: only work at the start of a line] Rust: /* */ Scala: /* */ SQL (MySQL): /* */ SQL (PostgreSQL): /* */ SQL (SQLite): /* */ Swift: /* */ UFL: OpConcat [concatenate][see also: StrConcat] AutoHotkey: . [also: string literal concatenation (and other types) (auto-concat) (e.g. '"abc" "def" 123' is equivalent to '"abcdef123"')] C++: + [WARNING: + for addition and concatenation] [also: string literal concatenation (e.g. '"abc" "def"' is equivalent to '"abcdef"')] C#: + [WARNING: + for addition and concatenation] Crystal: + [WARNING: + for addition and concatenation] Excel: & Excel VBA: & [also: +] [WARNING: + for addition and concatenation] Go: + [WARNING: + for addition and concatenation] Java: + [WARNING: + for addition and concatenation] JavaScript: + [WARNING: + for addition and concatenation] Kotlin: + [WARNING: + for addition and concatenation] PHP: . Python: + [WARNING: + for addition and concatenation] [also: string literal concatenation (e.g. '"abc" "def"' is equivalent to '"abcdef"')] R: [none] [can use: paste0(vText1, vText2)] [also: paste(vText1, vText2, sep="")] Ruby: + [WARNING: + for addition and concatenation] Rust: + [WARNING: + for addition and concatenation] Scala: + [WARNING: + for addition and concatenation] SQL (MySQL): || [MAJOR WARNING: use 'set sql_mode=PIPES_AS_CONCAT' to enable pipes as concat] [WARNING: unusual operator symbol] [WARNING: concatenates ints (not just strings)] [also: concat()] SQL (PostgreSQL): || [WARNING: unusual operator symbol] [WARNING: at least one operand must be a string] [also: concat()] SQL (SQLite): || [WARNING: unusual operator symbol] [WARNING: concatenates ints (not just strings)] [also: concat()] Swift: + [WARNING: + for addition and concatenation] UFL: OpLTStr/OpGTStr [string comparison (less than/greater than)][e.g. "A" > "a" should return false, and "A" < "a" true, since 65 < 97][see also: StrCompare] AutoHotkey: [none] [can use: StrCompare()] [WARNING (StrCompare): case-insensitive by default] C++: < > [e.g. ((std::string)"abc" < (std::string)"def")] [also (for char arrays): strcmp()] C#: [none] [can use: String.Compare()] Crystal: < > Excel: < > [WARNING: case-insensitive] [also (case-sensitive equals): EXACT(A1,B1)] Excel VBA: < > [note: case-sensitive (unlike sheet versions of < and >)] Go: < > Java: [none] [can use: compareTo()] JavaScript: < > Kotlin: < > PHP: < > Python: < > R: < > [WARNING: 'vText1 > vText2' may give an unintuitive result depending on the default collation] [note: for a more standard comparison, use locale 'C', e.g. Sys.setlocale("LC_COLLATE", "C")] Ruby: < > Rust: < > Scala: < > SQL (MySQL): < > [WARNING: case-insensitive] SQL (PostgreSQL): < > [e.g. MyCol1 > MyCol2 COLLATE "C"] [WARNING: 'MyCol1 > MyCol2' may give an unintuitive result depending on the default collation] SQL (SQLite): < > Swift: < > UFL: OpEquals [comparison (equality)][see also: StrEquals/DateClone/Any.Address] AutoHotkey: == [also (case-insensitive): =] C++: == [e.g. ((std::string)"abc" == (std::string)"def")] [also (for char arrays): strcmp()] C#: == Crystal: == Excel: = [note: case-insensitive] Excel VBA: = [case-sensitive (unlike Excel sheet formulae)] Go: == Java: == [note: == checks for referential equality] [also (compare values): oObj1.equals(oObj2)] JavaScript: == [also (strict equal): ===] [note (===): operands are equal and of the same type] Kotlin: == [also (referential equality): ===] PHP: == [also: ===] [note (==): equal after type juggling] Python: == [also (referential equality): is (inverse: is not)] [note: word order: 'not in' versus 'is not'] R: == Ruby: == [also (type-sensitive): oObj1.eql?(oObj2)] [also (compares object IDs, referential equality): oObj1.equal?(oObj2)] Rust: == Scala: == [also (referential equality): eq (inverse: ne)] SQL (MySQL): = [WARNING: case-insensitive] [also (null-safe equal): <=>] [WARNING: <=> does not do three-way comparison] SQL (PostgreSQL): = SQL (SQLite): = [also: ==] Swift: == UFL: OpNotEquals [comparison (not equals)] AutoHotkey: !== [note: case-insensitive: !=] [deprecated (AHK v1): <> (*case-insensitive* when comparing strings)] C++: != [e.g. ((std::string)"abc" != (std::string)"def")] [also (for char arrays): strcmp()] C#: != Crystal: != Excel: <> Excel VBA: <> [note: case-sensitive (unlike Excel sheet formulae)] Go: != Java: != JavaScript: != [also (strict not equal): !==] [note (!==): operands are of the same type but not equal, or are of different type] Kotlin: != [also (referential equality negated counterpart): !==] PHP: != [also: !==] [also: <>] [note (!= <>): not equal after type juggling] Python: != R: != Ruby: != Rust: != Scala: != SQL (MySQL): <> [also: !=] [WARNING (<> and !=): case-insensitive] SQL (PostgreSQL): <> [also: !=] SQL (SQLite): <> [also: !=] Swift: != UFL: OpInc [increment] AutoHotkey: i++ ++i i+=1 C++: i++ ++i i+=1 C#: i++ ++i i+=1 Crystal: i+=1 Excel: [none] Excel VBA: [none] [can use: i = i + 1] Go: i++ i+=1 Java: i++ ++i i+=1 JavaScript: i++ ++i i+=1 Kotlin: i++ ++i i+=1 PHP: $i++ ++$i $i+=1 Python: i+=1 R: [none] [can use: i = i + 1] Ruby: i+=1 [WARNING: the one-liner ++i is a noop, it returns i and discards it] [WARNING: the one-liner i++ tries to combine with the line underneath] Rust: i+=1 Scala: i+=1 SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: i+=1 UFL: OpDec [decrement] AutoHotkey: i-- --i i-=1 C--: i-- --i i-=1 C#: i-- --i i-=1 Crystal: i-=1 Excel: [none] Excel VBA: [none] [can use: i = i - 1] Go: i-- i-=1 Java: i-- --i i-=1 JavaScript: i-- --i i-=1 Kotlin: i-- --i i-=1 PHP: $i-- --$i $i-=1 Python: i-=1 R: [none] [can use: i = i - 1] Ruby: i-=1 [WARNING: the one-liner --i is a noop, it returns i and discards it] [WARNING: the one-liner i-- tries to combine with the line underneath] Rust: i-=1 Scala: i-=1 SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: i-=1 UFL: OpSubSubOrDecDemo [i.e. -- could be decrement or 'subtract subtract'][-- (applied to integer literals e.g. 15--10 = 25) (i.e. apply - twice) (i.e. binary minus then unary minus)] AutoHotkey: ___ [error] [WARNING: AHK v1: 15--10 returns 10, it should return 25] C++: ___ [error] C#: ___ [error] Crystal: ___ [error] Excel: works Excel VBA: works [note: '15--10' is auto-formatted to '15 - -10'] Go: ___ [error] Java: ___ [error] JavaScript: ___ [error] Kotlin: ___ [error] PHP: ___ [error] Python: works R: works Ruby: works Rust: works Scala: ___ [error] SQL (MySQL): works SQL (PostgreSQL): ___ [error] [WARNING: '15--10' is interpreted as '15' because '--' indicates a comment] [note: '15 - -10' returns 25 as expected] SQL (SQLite): ___ [error] [WARNING: '15--10' is interpreted as '15' because '--' indicates a comment] [note: '15 - -10' returns 25 as expected] Swift: ___ [error] UFL: OpAssign [assign][see also: SymCharEq] AutoHotkey: := [note (in AHK v1, sometimes): =] C++: = C#: = Crystal: = Excel: = [also: equals (comparison)] [note: *case-insensitive* when comparing strings] Excel VBA: = [also: equals (comparison) (case-sensitive when comparing strings)] Go: = [also (declare-and-assign one-liners): :=] [note: = to declare-and-assign or assign] Java: = JavaScript: = Kotlin: = PHP: = Python: = [also (sometimes): :=] R: <- [also: =] [also (non-local assignment operator, 'global assignment operator'): <<-] Ruby: = Rust: = Scala: = SQL (MySQL): = [WARNING: = sometimes does comparison] [also: :=] SQL (PostgreSQL): = [WARNING: = sometimes does comparison] SQL (SQLite): = [WARNING: = sometimes does comparison] Swift: = UFL: OpAnd [logical and][for some languages: inputs must be bools][for some languages: output is bool, for others: first truthy value] AutoHotkey: && [also: and] [note: takes any, returns value] [WARNING: AHK v1: returns bool] C++: && [note: takes any, returns bool (as int)] [WARNING: "" (char array) is considered truthy] C#: && [note: takes bool, returns bool] Crystal: && [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns value] Excel: [none] [can use: AND(A1,B1)] [note: takes bool/number, returns bool] Excel VBA: And [WARNING: bitwise-and when applied to numbers] [note: takes bool/number, returns value] Go: && [note: takes bool, returns bool] Java: && [note: takes bool, returns bool] JavaScript: && [note: takes any, returns value] Kotlin: && [note: takes bool, returns bool] PHP: && [note: takes any, returns bool] Python: and [note: takes any, returns value] R: && [note: takes bool/number, returns bool] Ruby: && [also: and] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns value] [WARNING: 'and' is higher precedence than '&&'] Rust: && [note: takes bool, returns bool] Scala: && [note: takes bool, returns bool] SQL (MySQL): AND [also: &&] [note: takes any, returns bool (as int)] SQL (PostgreSQL): AND [note: takes bool, returns bool] SQL (SQLite): AND [note: takes any, returns bool (as int)] Swift: && [note: takes bool, returns bool] UFL: OpOr [logical or][for some languages: inputs must be bools][for some languages: output is bool, for others: first truthy value] AutoHotkey: || [also: or] [note: takes any, returns value] [WARNING: AHK v1: returns bool] C++: || [note: takes any, returns bool (as int)] [WARNING: "" (char array) is considered truthy] C#: || [note: takes bool, returns bool] Crystal: || [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns value] Excel: [none] [can use: OR(A1,B1)] [note: takes bool/number, returns bool] Excel VBA: Or [WARNING: bitwise-or when applied to numbers] [note: takes bool/number, returns value] Go: || [note: takes bool, returns bool] Java: || [note: takes bool, returns bool] JavaScript: || [note: takes any, returns value] Kotlin: || [note: takes bool, returns bool] PHP: || [note: takes any, returns bool] Python: or [note: takes any, returns value] R: || [note: takes bool/number, returns bool] Ruby: || [also: or] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns value] [WARNING: 'or' is higher precedence than '||'] Rust: || [note: takes bool, returns bool] Scala: || [note: takes bool, returns bool] SQL (MySQL): OR [also: ||] [WARNING: || does concatenation if use 'set sql_mode=PIPES_AS_CONCAT'] [note: takes any, returns bool (as int)] SQL (PostgreSQL): OR [WARNING: || does concatenation] [note: takes bool, returns bool] SQL (SQLite): OR [WARNING: || does concatenation] [note: takes any, returns bool (as int)] Swift: || [note: takes bool, returns bool] UFL: OpOrIntDemo [|| (whether it returns a bool or an operand)][i.e. whether it's equivalent to a short-ternary operator][for some languages, cannot use ints with ||][see also: OpShortTern] AutoHotkey: 0 || 123 [output: 123] [note: AHK v1: returns 1 (i.e. True)] C++: 0 || 123 [output: 1 (i.e. True)] C#: 0!=0 || 123!=0 [output: True] Crystal: 0 || 123 [output: 0] [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: OR(0,123) [output: TRUE] Excel VBA: 0 Or 123 [output: 123] [note: bitwise-or] Go: 0 != 0 || 123 != 0 [output: true] Java: 0!=0 || 123!=0 [output: true] JavaScript: 0 || 123 [output: 123] Kotlin: 0!=0 || 123!=0 [output: true] [WARNING: in Kotlin, '?:' is a null-coalescing operator, not a short-ternary operator: e.g. '0 ?: 123' returns 0, since 0 is non-null] PHP: 0 || 123 [output: 1 (i.e. True)] [note: '0 ?: 123' returns 123] Python: 0 or 123 [output: 123] R: 0 || 123 [output: TRUE] Ruby: 0 || 123 [output: 0] [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: 0!=0 || 123!=0 [output: true] Scala: 0!=0 || 123!=0 [output: true] SQL (MySQL): 0 OR 123 [output: 1 (i.e. true)] SQL (PostgreSQL): 0!=0 OR 123!=0 [output: t (i.e. true)] SQL (SQLite): 0 OR 123 [output: 1 (i.e. true)] Swift: 0 != 0 || 123 != 0 [output: true] [note: '0 || 123' is invalid] UFL: OpNot [logical not][see also: IsTruthy] AutoHotkey: ! [also: not] [WARNING: !/not have different operator precedences] [note: takes any, returns bool (as int)] C++: ! [note: takes any, returns bool (as int)] [WARNING: "" (char array) is considered truthy] C#: ! [note: takes bool, returns bool] Crystal: ! [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns bool] Excel: [none] [can use: NOT(A1)] [note: takes bool/number, returns bool] Excel VBA: Not [WARNING: bitwise-not when applied to numbers] [can use (ints): (vValue = 0)] [note: takes bool/number, returns value] Go: ! [note: takes bool, returns bool] Java: ! [note: takes bool, returns bool] JavaScript: ! [note: takes any, returns bool] Kotlin: ! [note: takes bool, returns bool] PHP: ! [note: takes any, returns bool] Python: not [note: takes any, returns bool] R: ! [note: takes bool/number, returns bool] [also: isTRUE(), isFALSE()] Ruby: ! [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] [note: takes any, returns bool] Rust: ! [WARNING: bitwise-not when applied to ints] [can use (ints): (vValue == 0)] [WARNING: accepts ints, unlike && and ||] [note: takes bool/int, returns value] Scala: ! [note: takes bool, returns bool] SQL (MySQL): NOT [also: !] [note: takes any, returns bool (as int)] [MAJOR WARNING: in MySQL, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] SQL (PostgreSQL): NOT [note: takes bool, returns bool] SQL (SQLite): NOT [note: takes any, returns bool (as int)] [MAJOR WARNING: in SQLite, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] Swift: ! [note: takes bool, returns bool] UFL: OpNotIntDemo [logical not applied to integers (e.g. !123)] AutoHotkey: 0 [note: bool stored as int] C++: 0 [note: bool stored as int] C#: error [note: !true returns false] Crystal: false [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: FALSE [note: NOT(123) returns FALSE] Excel VBA: -124 [WARNING: bitwise-not when applied to numbers] [note: (123 = 0) returns False] Go: error [note: !true returns false] Java: error [note: !true returns false] JavaScript: false Kotlin: error [note: !true returns false] PHP: false Python: False [note: not 123 returns False] R: FALSE Ruby: false [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: -124 [WARNING: bitwise-not when applied to ints] [note: (123 == 0) returns false] Scala: error [note: !true returns false] SQL (MySQL): 0 [note: NOT 123 returns 0 (i.e. false)] SQL (PostgreSQL): error [note: NOT true returns f (i.e. false)] SQL (SQLite): 0 [note: NOT 123 returns 0 (i.e. false)] Swift: error [note: !true returns false] UFL: OpNotStrDemo [logical not applied to strings (e.g. !"abc")] AutoHotkey: 0 [note: bool stored as int] C++: 0 [note: bool stored as int] [WARNING: '!' applied to any char array returns 0] [note: '!' applied to a std::string throws] C#: error [note: !true returns false] Crystal: false [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: error [note: NOT() in Excel returns an error on strings] Excel VBA: error [note: 'Not' in Excel VBA throws on strings] [note: ("abc" = "") returns False] Go: error [note: !true returns false] Java: error [note: !true returns false] JavaScript: false Kotlin: error [note: !true returns false] PHP: false Python: False [note: not "abc" returns False] R: error Ruby: false [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: error [note: ("abc" == "") returns false] Scala: error [note: !true returns false] SQL (MySQL): 1 [note: NOT "abc" returns 1 (i.e. true)] [MAJOR WARNING: in MySQL, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] SQL (PostgreSQL): error [note: NOT true returns f (i.e. false)] SQL (SQLite): 1 [note: NOT "abc" returns 1 (i.e. true)] [MAJOR WARNING: in SQLite, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] Swift: error [note: !true returns false] UFL: OpNotNotIntDemo [logical not applied to integers twice (e.g. !!123)] AutoHotkey: 1 [note: bool stored as int] C++: 1 [note: bool stored as int] C#: error [note: !!true returns true] Crystal: true [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: TRUE [note: NOT(NOT(123)) returns TRUE] Excel VBA: 123 [WARNING: bitwise-not when applied to numbers] [note: ((123 = 0) = False) returns True] Go: error [note: !!true returns true] Java: error [note: !!true returns true] JavaScript: true Kotlin: error [note: !!true returns true] PHP: true Python: True [note: not not 123 returns True] R: TRUE Ruby: true [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: 123 [WARNING: bitwise-not when applied to ints] [note: ((123 == 0) == false) returns true] Scala: error [note: !(!true) returns true] SQL (MySQL): 1 [note: NOT NOT 123 returns 1 (i.e. true)] SQL (PostgreSQL): error [note: NOT NOT true returns t (i.e. true)] SQL (SQLite): 1 [note: NOT NOT 123 returns 1 (i.e. true)] Swift: error [note: !(!true) returns true] [WARNING: error if attempt '!!': 'unary operators must not be juxtaposed'] UFL: OpNotNotStrDemo [logical not applied to strings twice (e.g. !!"abc")] AutoHotkey: 1 [note: bool stored as int] C++: 1 [note: bool stored as int] [WARNING: '!' applied to any char array returns 0] [note: '!' applied to a std::string throws] C#: error [note: !!true returns true] Crystal: true [MAJOR WARNING: in Crystal, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: error [note: NOT() in Excel returns an error on strings] Excel VBA: error [note: 'Not' in Excel VBA throws on strings] [note: (("abc" = "") = False) returns True] Go: error [note: !!true returns true] Java: error [note: !!true returns true] JavaScript: true Kotlin: error [note: !!true returns true] PHP: true Python: True [note: not not "abc" returns True] R: error Ruby: true [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: error [note: (("abc" == "") == false) returns true] Scala: error [note: !(!true) returns true] SQL (MySQL): 0 [note: NOT NOT "abc" returns 0 (i.e. false)] [MAJOR WARNING: in MySQL, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] SQL (PostgreSQL): error [note: NOT NOT true returns t (i.e. true)] SQL (SQLite): 0 [note: NOT NOT "abc" returns 0 (i.e. false)] [MAJOR WARNING: in SQLite, some non-blank strings are considered falsy (e.g. 'abc' is falsy, '123abc' is truthy), strings are cast to numeric, then numeric to 1 or 0] Swift: error [note: !(!true) returns true] [WARNING: error if attempt '!!': 'unary operators must not be juxtaposed'] UFL: (OpPowUnaryAddDemo) [confirm whether the power operator has higher precedence than the unary add operator][e.g. confirm that (-3 ** 2) == -9, the answer given by WolframAlpha][see also: OpPow] AutoHotkey: -9 C++: (no pow operator) C#: (no pow operator) Crystal: 9 [WARNING: -9 expected] [note: differs from Ruby] Excel: 9 [WARNING: -9 expected] [note: differs from Excel VBA] Excel VBA: -9 [note: differs from Excel sheets] Go: (no pow operator) Java: (no pow operator) JavaScript: error [e.g. error message: 'Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence'] Kotlin: (no pow operator) PHP: -9 Python: -9 R: -9 Ruby: -9 Rust: (no pow operator) Scala: (no pow operator) SQL (MySQL): (no pow operator) SQL (PostgreSQL): 9 [WARNING: -9 expected] SQL (SQLite): (no pow operator) Swift: (no pow operator) UFL: (OpBitOrEqualsDemo) [confirm whether the bitwise-or operator has higher precedence than the equals operator][e.g. confirm that (2 | 1 == 3) == true][note: it is an oddity in C that == is of higher precedence than & ^ |][see also: BitOr/OpEquals] AutoHotkey: | has precedence over == C++: == has precedence over | [WARNING: == has higher precedence, '(2 | 1 == 3)' returns 2, however, a compiler warning is given] C#: == has precedence over | [WARNING: == has higher precedence, however '(2 | 1 == 3)' would give 'int | bool', and thus throws] Crystal: | has precedence over == Excel: (no bitwise-or operator) Excel VBA: = has precedence over Or (bitwise and logical) [WARNING: = has higher precedence, '(2 Or 1 = 3)' returns 2] Go: | has precedence over == Java: == has precedence over | [WARNING: == has higher precedence, however '(2 | 1 == 3)' would give 'int | bool', and thus throws] JavaScript: == has precedence over | [WARNING: == has higher precedence, '(2 | 1 == 3)' returns 2] Kotlin: 'or' has precedence over == PHP: == has precedence over | [WARNING: == has higher precedence, '(2 | 1 == 3)' returns 2] Python: | has precedence over == R: (no bitwise-or operator) Ruby: | has precedence over == Rust: | has precedence over == Scala: == has precedence over | [WARNING: == has higher precedence, however '(2 | 1 == 3)' would give 'int | bool', and thus throws] SQL (MySQL): | has precedence over = SQL (PostgreSQL): | has precedence over = SQL (SQLite): | has precedence over == Swift: | has precedence over == UFL: OpMemberAccess [member access][property access][see also: Object.GetDemo/Object.SetDemo] AutoHotkey: . C++: . [also (if pointer to an object): ->] [also (class (static) members): ::] C#: . Crystal: . [also (class (static) members): ::] Excel: [none] Excel VBA: . Go: . Java: . JavaScript: . Kotlin: . PHP: -> [also (class (static) members): ::] Python: . R: $ [also: @] [note: $ for S3 class and reference class] [note: @ for S4 class] [also (to set a property value in a method): <<-] Ruby: . [also (class (static) members): ::] Rust: . [also (class (static) members): ::] Scala: . SQL (MySQL): [none] [also (JSON strings): -> and ->>] SQL (PostgreSQL): [none] [also (JSON strings): -> and ->>] SQL (SQLite): [none] [also (JSON strings): -> and ->>] Swift: . UFL: OpSafeNav [or OpNullChain][safe navigation operator (optional chaining operator)][e.g. if a member contains null, return null, i.e. do an early exit, don't attempt to read any descendant members][note: typically, if a member exists and contains null, early exit return null, if a member doesn't exist, throw][e.g. (from Wikipedia): name = article?.author?.name][e.g. a?.b?.c, a may be null (early exit), a.b may be null (early exit), a.b.c may be null] AutoHotkey: [none] C++: [none] C#: ?. [e.g. vValue = oObj?.MyProp] [e.g. vValue = oArray?[vKey]] [e.g. vValue = oFunc?.Invoke(vArg1, vArg2, vArg3)] [name: null-conditional member access operator] Crystal: ___ [can use: '.try &.', e.g. a.try &.b.try &.c] [e.g. vValue = oObj.try &.MyProp] [note: no subscript shorthand] [e.g. vValue = oFunc.try &.call(vArg1, vArg2, vArg3)] Excel: [none] Excel VBA: [none] Go: [none] Java: [none] JavaScript: ?. [e.g. vValue = oObj?.MyProp] [e.g. vValue = oArray?.[vKey]] [e.g. vValue = oFunc?.(vArg1, vArg2, vArg3)] [name: optional chaining operator] Kotlin: ?. [e.g. vValue = oObj?.MyProp] [e.g. vValue = oArray?.get(vKey)] [e.g. vValue = oFunc?.invoke(vArg1, vArg2, vArg3)] [name: safe call operator] [e.g. array of nullable ints: var oArray = arrayOf<Int?>(1, 2, 3)] [e.g. nullable function: var oFunc: ((Int) -> Int)? = {vNum:Int -> vNum*2}] PHP: ?-> [e.g. $vValue = $oObj?->MyProp] [note: no subscript shorthand] [note: no function call shorthand] [name: null-safe operator] Python: [none] R: [none] Ruby: &. [e.g. vValue = oObj&.MyProp] [note: no subscript shorthand] [e.g. vValue = oFunc&.call(vArg1, vArg2, vArg3)] [name: safe navigation operator] Rust: [none] [can use (acts like a return if sees a None, e.g. '?.'): ?] [also: oOpt.map()] [also: oOpt.and_then()] Scala: [none] SQL (MySQL): [none] SQL (PostgreSQL): [none] SQL (SQLite): [none] Swift: ?. [e.g. vValue = oObj?.MyProp] [e.g. (optional subscript operator): oArray?[vKey]] [e.g. (optional call): vValue = oFunc?(vArg1, vArg2, vArg3)] [name: optional chaining operator] [e.g. nullable struct: var oObj:MyStruct? = MyStruct()] [e.g. nullable array of nullable ints: oArray:[Int?]? = [1,2,3]] [e.g. nullable function: var oFunc: ((_ vNum: Int) -> Int)? = {vNum in vNum*2}] UFL: SymPfxBin/SymPfxOct/SymPfxHex [prefixes for bin/oct/hex numbers][binary/octal/hexadecimal] AutoHotkey: [none]/[none]/0x C++: 0b/0/0x [WARNING: a leading '0' is a prefix for octal] C#: 0b/[none]/0x Crystal: 0b/0o/0x Excel: [none]/[none]/[none] [can use: BIN2DEC/OCT2DEC/HEX2DEC] Excel VBA: [none]/&O/&H [can use: WorksheetFunction.Bin2Dec(vBin)] [note: Visual Basic 2017 has &B] [note: WorksheetFunction.Bin2Dec/Application.WorksheetFunction.Bin2Dec return a String, Application.Bin2Dec returns a Double] Go: 0b/0o/0x Java: 0b/[none]/0x JavaScript: 0b/0o/0x Kotlin: 0b/[none]/0x PHP: 0b/0o/0x Python: 0b/0o/0x R: [none]/[none]/0x Ruby: 0b/0o/0x Rust: 0b/0o/0x Scala: [none]/[none]/0x SQL (MySQL): 0b/[none]/0x [MAJOR WARNING: '0b' and '0x' prefixes create strings, use vNum + 0 to cast to a number] [also: B'10' and X'10', which also produce strings] SQL (PostgreSQL): 0b/0o/0x SQL (SQLite): [none]/[none]/0x Swift: 0b/0o/0x UFL: SymSepNum [numeric literal separator (digit separator)][break up long numbers (for better readability)] AutoHotkey: [none] [can use: vNum := Number(StrReplace("1_234_567", "_"))] C++: ' C#: _ Crystal: _ Excel: [none] [can use: =0+SUBSTITUTE("1_234_567","_","")] Excel VBA: [none] [can use: vNum = 0 + Replace("1_234_567", "_", "")] [note: Visual Basic 2017 has _] Go: _ Java: _ JavaScript: _ Kotlin: _ PHP: _ Python: _ R: [none] [can use: vNum = as.numeric(gsub("_", "", "1_234_567"))] Ruby: _ Rust: _ Scala: _ SQL (MySQL): [none] SQL (PostgreSQL): _ SQL (SQLite): _ Swift: _
UFL: SymCharSlashInt [/ (applied to integers)][typically true division, or C-style integer division (truncated division): divide then round towards zero (truncate)][see also: TrueDiv/TruncDiv/FloorDiv] AutoHotkey: true division C++: truncated division [WARNING: not true division] C#: truncated division [WARNING: not true division] Crystal: true division Excel: true division Excel VBA: true division Go: truncated division [WARNING: not true division] Java: truncated division [WARNING: not true division] JavaScript: true division Kotlin: truncated division [WARNING: not true division] PHP: true division Python: true division [note: Python 1 and 2: floor division] R: true division Ruby: floor division [WARNING: not true division] Rust: truncated division [WARNING: not true division] Scala: truncated division [WARNING: not true division] SQL (MySQL): true division SQL (PostgreSQL): truncated division [WARNING: not true division] SQL (SQLite): truncated division [WARNING: not true division] Swift: truncated division [WARNING: not true division] UFL: SymCharSlashFloat [/ (applied to floats)][see also: TrueDiv] AutoHotkey: true division C++: true division C#: true division Crystal: true division Excel: true division Excel VBA: true division Go: true division Java: true division JavaScript: true division Kotlin: true division PHP: true division Python: true division R: true division Ruby: true division Rust: true division Scala: true division SQL (MySQL): true division SQL (PostgreSQL): true division SQL (SQLite): true division Swift: true division UFL: SymCharSlashSlash [//] AutoHotkey: truncated division [note: in AHK v1: sometimes floor division] C++: comment C#: comment Crystal: floor division Excel: ___ Excel VBA: ___ Go: comment Java: comment JavaScript: comment Kotlin: comment PHP: comment Python: floor division R: ___ Ruby: ___ Rust: comment Scala: comment SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: comment UFL: SymCharPct [%][note: typically C-style modulo (truncated modulo)][see also: Mod/FloorMod] AutoHotkey: ___ [can use (truncated modulo, ints/floats): Mod(vNum1, vNum2)] C++: truncated modulo [note: ints only] C#: truncated modulo [note: ints/floats] Crystal: floor modulo [WARNING: % as floor modulo is uncommon] [note: ints/floats] [WARNING: mathematical operator used on strings: % also performs sprintf] Excel: ___ [can use (floor modulo, ints/floats): MOD(A1,B1)] [WARNING: Excel's MOD is a floor mod, Excel VBA's Mod operator is a truncated mod] Excel VBA: ___ [can use (truncated modulo, Mod operator, for safety use ints only): vNum1 Mod vNum2] [MAJOR WARNING: Mod operator rounds operands before calculating (note: Excel's sheet function MOD does not do this)] Go: truncated modulo [note: ints only] Java: truncated modulo [note: ints/floats] JavaScript: truncated modulo [note: ints/floats] Kotlin: truncated modulo [note: ints/floats] PHP: truncated modulo [note: for safety use ints only] [MAJOR WARNING: % truncates operands before calculating] Python: floor modulo [WARNING: % as floor modulo is uncommon] [note: ints/floats] [WARNING: mathematical operator used on strings: % is also the string formatting operator] R: ___ [can use (floor modulo, ints/floats): vNum1 %% vNum2] Ruby: floor modulo [WARNING: % as floor modulo is uncommon] [note: ints/floats] [WARNING: mathematical operator used on strings: % also performs sprintf] Rust: truncated modulo [note: ints/floats] Scala: truncated modulo [note: ints/floats] SQL (MySQL): truncated modulo [note: ints/floats] [also: MOD operator] [also: mod()] SQL (PostgreSQL): truncated modulo [note: ints/floats] [also: mod()] SQL (SQLite): truncated modulo [note: for safety use ints only] [MAJOR WARNING: % truncates operands before calculating] [also: mod()] Swift: truncated modulo [note: ints only] UFL: SymCharApos [' (single quotes) (apostrophes)][see also: SymCharLiteral/SymInterpolateDemo/JsonArrayDemo/JsonObjectDemo] AutoHotkey: literal strings [note: AHK v2 onwards] C++: characters [note: ' is also a numeric literal separator] C#: characters Crystal: characters Excel: ___ Excel VBA: comments Go: characters Java: characters JavaScript: literal strings Kotlin: characters PHP: literal strings Python: literal strings R: literal strings Ruby: literal strings Rust: characters Scala: characters SQL (MySQL): literal strings [also: "] [note: ` is used for identifiers (e.g. column names)] SQL (PostgreSQL): literal strings [WARNING: double quotes are used for identifiers (e.g. column names)] SQL (SQLite): literal strings [WARNING: double quotes are used for column names] Swift: ___ UFL: SymCharEq [=][see also: OpAssign] AutoHotkey: equals [note: *case-insensitive* when comparing strings] C++: assign C#: assign Crystal: assign Excel: assign [also: equals (comparison)] [note: *case-insensitive* when comparing strings] Excel VBA: assign [also: equals (comparison) (case-sensitive when comparing strings)] Go: assign [also (declare-and-assign one-liners): :=] [note: = to declare-and-assign or assign] Java: assign JavaScript: assign Kotlin: assign PHP: assign Python: assign R: assign [also: <-] Ruby: assign Rust: assign Scala: assign SQL (MySQL): assign [also: comparison] SQL (PostgreSQL): assign [also: comparison] SQL (SQLite): assign [also: comparison] Swift: assign UFL: SymCharEqEq [==] AutoHotkey: equals [note: case-sensitive when comparing strings] C++: equals C#: equals Crystal: equals Excel: ___ Excel VBA: ___ Go: equals Java: equals JavaScript: equals Kotlin: equals PHP: equal after type juggling [note: most languages use a form of 'type juggling' when comparing] Python: equals R: equals Ruby: equals Rust: equals Scala: equals SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): equals Swift: equals UFL: SymCharEqEqEq [===] AutoHotkey: ___ C++: ___ C#: ___ Crystal: case subsumption operator [i.e. is right operand a member of left operand] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: strict equal [note: operands are equal and of the same type] Kotlin: referential equality [note: true iff point to same object] PHP: equal and of the same type Python: ___ R: ___ Ruby: case equality operator [i.e. is right operand a member of left operand] [e.g. used in case statements] Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: SymCharExclEq [!=] AutoHotkey: not equal [note: *case-insensitive* when comparing strings] C++: not equal C#: not equal Crystal: not equal Excel: ___ Excel VBA: ___ Go: not equal Java: not equal JavaScript: not equal Kotlin: not equal PHP: not equal after type juggling Python: not equal R: not equal Ruby: not equal Rust: not equal Scala: not equal SQL (MySQL): not equal SQL (PostgreSQL): not equal SQL (SQLite): not equal Swift: not equal UFL: SymCharExclEqEq [!==] AutoHotkey: not equal [note: case-sensitive when comparing strings] C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: strict not equal [note: operands are of the same type but not equal, or are of different type] Kotlin: referential equality negated counterpart PHP: not equal or not of the same type Python: ___ R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): ___ SQL (PostgreSQL): ___ SQL (SQLite): ___ Swift: ___ UFL: SymCharLtGt [<>] AutoHotkey: ___ [deprecated (AHK v1): (*case-insensitive* when comparing strings)] C++: ___ C#: ___ Crystal: ___ Excel: not equal [note: *case-insensitive* when comparing strings] Excel VBA: not equal [note: case-sensitive when comparing strings] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: not equal after type juggling Python: ___ [deprecated: was available in Python v2] R: ___ Ruby: ___ Rust: ___ Scala: ___ SQL (MySQL): not equal SQL (PostgreSQL): not equal SQL (SQLite): not equal Swift: ___
In mathematics, and programming, calculations do not simply occur from left-to-right, you have to consider the relative precedences of the operators. E.g. 1 + 2 - 3 * 4 / 5 This is equivalent to: (1 + 2) - ((3 * 4) / 5) = 0.6 I.e. * and / have a higher precedence than + and -. This is called order of operations, and common mnemonics for operator precedence are BODMAS and PEMDAS, to help you remember which operators have the higher precedence. Programming languages typically have an operator precedence table. Various such tables are listed on this website, here: Documentation Links. In programming it is generally wise not to rely 100% on the documentation, but to perform your own tests, to confirm that the documentation is in fact correct. The documentation may be incorrect or out-of-date, or there may be a bug in the programming language. There may even be a bug in the microchip, causing errors in calculations. What follows are some lines of code for testing operator precedence. In each test, the pseudocode returns true if the programming language uses the more common operator precedence. * is of higher precedence than binary + Pseudocode: vRetMulAdd = (2 * 3 + 4) == 10 To confirm the precedence of two operators, you want a formula/expression, that would have two different possible answers, depending on which operator has precedence. E.g. 2 * 3 + 4. If + was of higher precedence, the answer would be 2 * (3 + 4) = 14. If * was of higher precedence, the answer would be (2 * 3) + 4 = 10. The answer is 10, so * has higher precedence. ** is of higher precedence than unary - Pseudocode: vRetPowUnAdd = (- 3 ** 2) == -9 See the section 'OpPowUnaryAddDemo' above, which compares the results for various programming languages. Many programming languages lack a power operator, the tests below however, should be applicable to virtually all programming languages. % is of higher precedence than binary + Pseudocode: vRetModAdd = (10 % 5 + 2) == 2 && is of higher precedence than || Pseudocode: vRetAndOr1 = (false && false || true) == true vRetAndOr2 = (false && true || true) == true Note: '2 choose 3' with repetitions, gives 8 permutations: FFF, FFT, FTF, FTT, TFF, TFT, TTF, TTT. Listed above are the 2 out of 8 permutations that give distinct answers. I.e. the tests differ, but both serve the same purpose, to confirm that && has a higher precedence than ||. Note: C++ debuggers may give a warning for this particular example, suggesting that the user add parentheses for clarity/safety. == is of higher precedence than || Pseudocode: vRetEqOr1 = (false == false || true) == true vRetEqOr2 = (false == true || true) == true Listed above are the 2 out of 8 permutations that give distinct answers. == is of higher precedence than && Pseudocode: vRetEqAnd1 = (false == false && false) == false vRetEqAnd2 = (false == true && false) == false Listed above are the 2 out of 8 permutations that give distinct answers. << is of higher precedence than | Pseudocode: vRetBitShiftBitOr = (1 << 8 | 2) == 258 | is of higher precedence than == Pseudocode: vRetBitOrEq = (2 | 1 == 3) == true This relates to an oddity in C, and various languages that derive from it (e.g. C++/C#/Java/JavaScript/PHP/Scala). In C: 2 | 1 == 3 is equivalent to: 2 | (1 == 3) rather than the likely more reasonable/useful: (2 | 1) == 3 The same applies to & and ^. The operator precedence table for C has the full list. Note: '2 | (1 == 3)' is impossible in many languages because they disallow 'int | bool'. See the section 'OpBitOrEqualsDemo' above, which compares the results for various programming languages. Author's view: most of the time C gets it right, it had the best syntax of any programming language in its day, and has been probably the number one source of/influence for good syntax in programming languages. && is of higher precedence than = Pseudocode: vTemp = true && false vRetAssignAnd = vTemp == false This relates to an oddity in Ruby. '&&' and 'and' are both operators, and most of the time equivalent. As is common in most programming languages, && has higher precedence than =, however, = has higher precedence than 'and'. So, 'vTemp = true && false' is equivalent to 'vTemp = (true && false)'. But, 'vTemp = true and false' is equivalent to '(vTemp = true) and false'. Common operator precedences Some common precedences, from highest to lowest, representative of many but not all programming languages: Starting with the C operator precedence table, with additions/differences noted. Operator precedence table: :: (scope resolution) [C++] ++ -- (suffix) [C] () (function call) [C] [] (array subscript) [C] . (member access) [C] [] (array subscript) [JavaScript] new (with arguments) [JavaScript] () (function call) [JavaScript] new (without arguments) [JavaScript] -> (member access) [C] ++ -- (suffix) [JavaScript] ++ -- (prefix) [C] + - (unary) [C] ! ~ [C] (type) [C] * (indirection) [C] & (address-of) [C] sizeof [C] new [C] ** [JavaScript] * / % [C] + - (binary) [C] << >> [C] << >> >>> [JavaScript] & [Python/Ruby] ^ [Python/Ruby] | [Python/Ruby] <=> [C++] < <= > >= [C] == != [C] === !== [JavaScript] & [C/C++/C#/JavaScript/PHP] ^ [C/C++/C#/JavaScript/PHP] | [C/C++/C#/JavaScript/PHP] && [C] || [C] ?? [JavaScript] ? : [C] throw [C++] = [C] += -= [C] *= /= %= [C] <<= >>= [C] &= ^= |= [C] ? : [JavaScript] => [JavaScript] ... [JavaScript] , [C]
role: common operators in many languages: + [add][sometimes concatenate] - [subtract] * [multiply][sometimes dereference (indirection), sometimes splat/spread][Python: WARNING: repeat string] / [divide] ** [power][note: not in C++][sometimes double splat] see below: ~ & | ^ [bitwise: not/and/or/xor] see below: ! && || [logical: not/and/or] ~ [bitwise not][C++/C#: ~ is used for class destructors] & [bitwise and][Visual Basic: & is concatenate][C++: & is also address-of] | [bitwise or] ^ [bitwise xor][^ is sometimes power] ! [logical not (logical negation)][Swift: unwrap optional][Rust: WARNING: ! is also bitwise-not (and used for macro expansion)][Crystal/Ruby: ! performs array operations in-place, without '!': returns a new array, e.g. flatten/reverse/shuffle/sort/uniq] && [logical and] || [logical or] ? : [ternary operator] << >> >>> [bitshift: left/right (signed)/right (logical/unsigned/zero-fill)][C++: << and >> can mean output/input] == [equals] != <> [not equal (inequality)] < > [less than/greater than][sometimes used as angle brackets (e.g. HTML)][Python: comparison operators can be chained e.g. x < y < z] <= >= [less than or equal to/greater than or equal to] % [modulo (modulus)][Excel: % is equivalent to '/100'][Ruby: % also performs sprintf] role: assignment operators: = [assign][can be used for function parameter default values] := [assign][walrus operator][can be used for function parameter default values] ++ [increment] -- [decrement][SQL: single-line comments] role: operators (augmented assignment versions): += -= *= /= **= &= |= ^= >>= <<= >>>= .= %= ??= //= ~/= \= role: operators further: ~/ [C-style (truncated) integer division (e.g. Dart)][corkscrew operator (author's name proposal)] // [floor division (e.g. Python)][often a comment symbol] %% [floormod (floor modulo) (e.g. R)] role: operators further: <=> [comparison][spaceship operator][e.g. C++/Perl/PHP/Ruby] !== [not equal (type safe)] === [equals (type safe)] => [fat-arrow function][PHP: key-value pair definitions] -> [C++: member access (structure pointer operator)][Kotlin: lambda expression, declaring function types][PHP: property access] ?: [short-ternary operator (Elvis operator)][note: checks true/false][note: sometimes || is equivalent (e.g. JavaScript)][WARNING: in some languages, checks non-null/null (a null-coalescing operator) e.g. Kotlin] ?? [null-coalescing operator][note: non-null/null] ... [spread/splat][note: Swift: also for closed ranges][note: Ruby: range (exclusive end)] .. [range][e.g. Haskell/Kotlin/Pascal/Perl/Ruby: inclusive end, e.g. C#/Rust: WARNING: exclusive end] ..< [range][e.g. Kotlin: range until, Swift: half-open range] ..= [range][e.g. Rust: inclusive end] : [range][e.g. R: inclusive end] . [member access][AutoHotkey/Perl/PHP: concatenate] ~= [AutoHotkey: RegExMatch] =~ [Ruby: RegEx match] !~ [Ruby: RegEx not match] :: [C++: scope qualifier (and for class out-of-line definitions: declare inside class, define elsewhere)][AutoHotkey: hotkey/hotstring][Kotlin: reference] # [directives][JavaScript: class private fields][Crystal/Ruby: string interpolation] ::<> [Rust: turbofish operator (specify a type, e.g. '::<i32>'/'::<String>')] %/% [R: floor division] role: comments: // [single-line comments] ; [single-line comments][e.g. AutoHotkey/FASM] # [single-line comments][e.g. Perl/PHP/Python/Ruby (PHP also uses //)] ' [single-line comments][e.g. Visual Basic] /* */ [multi-line comments (and single-line comments)][CSS comments] <!-- --> [HTML comments] :: [single-line comments][e.g. batch files] ''' [(3 apostrophes) bare string literals can be used as comments][e.g. Python] """ [bare string literals can be used as comments][e.g. Python] role: further symbols/operators: and [logical AND] or [logical OR] not [logical NOT] new [create object: create new instance of class] mod [modulo][Visual Basic has 'Mod' operator] in [is item in object] !in [is item not in object][e.g. Kotlin] , [separate statements] ; [separate statements] [ ] [get object value (aka subscript)] { } [scope][define object][noop][string interpolation] ( ) [group][note: '(mytype)' can be used for casting] @ [email addresses][R: member access] _ [often used as a variable name, during loops, for a variable that needs a name but isn't used][numeric literal separator][Swift: unnamed parameter/label][sometimes used as a prefix for an object property name intended to be private] __ [Python: 'dunder' (double underscore): a prefix and suffix for object 'magic method' names (which are intended to be private)] : [object property assignment e.g. {"myprop": 123}] ?. [optional chaining operator] &. [Crystal/Ruby: safe navigation operator] " " [literal string][string literal concatenation (juxtaposition) e.g. AutoHotkey/C/C++/Python/Ruby] ' ' [literal string][char e.g. C/C++/C#/Java/Kotlin/Rust][string literal concatenation (juxtaposition) e.g. AutoHotkey/Python/Ruby] ' [C++: numeric literal separator] \ [string escape character][Visual Basic: integer division] ` [JavaScript: template literals][AutoHotkey: string escape character] $ [string interpolation (inside literal strings)][R: member access] role: RegEx: \.*?+[{|()^$ [12 characters that need escaping in RegEx generally] ^-]\ [4 characters that need escaping in a RegEx character class] $()*+-.?[\]^{| [14 characters listed above (^ and \ appear twice)] !"#%&',/:;<=>@_`}~ [18 characters not listed above from the 'classic 32'] $ [sometimes needs escaping when doing a RegEx replace] [note: PHP: preg_quote escapes the 14, and also these 7: '!#:<=>}'] [note: Python: re.escape escapes the 14, and also these 4: '#&}~'] [note: C#: Regex.Escape escapes the 12, and also this 1: '#'] [note: Kotlin: Regex.escape uses '\Q...\E' to escape, and correctly handles literal '\E']
Listed in Appendix A's Syntax Summary (pp. 214-219): unary: * & - ! ~ ++ -- binary: * / % + - >> << < > <= >= == != & ^ | && || ? : assignment: = += -= *= /= %= >>= <<= &= ^= |= also (scattered throughout Syntax Summary): ( ) , [ ] . -> ; { } : " " < > # (note: ':' in structs, '< >' with #include) not in Syntax Summary (but are in Appendix A): /* */ ' ' \ (note: '/* */' for comments, '' '' for characters, '\' for escape characters) (note: '//' was *not* available as a comment character until C99 (1999)) (note: when C++ was first released in 1985, it had both comment styles: '/* */' and '//')
a blueprint for ideal operators: + += [addition, *NOT* concatenation (safer to restrict '+' to numbers only)] - -= [subtraction] * *= [multiplication and spread operator (for function calls and definitions)] / /= [true division (i.e. int/int=float)] ~/ ~/= [C-style (truncated) integer division (e.g. Dart)] ~~/ ~~/= [floor division (author's proposal), least worst option so far] ** **= [exponentiation] . .= [concatenation, and member access] ~ & | ^ &= |= ^= [bitwise: not/and/or/xor] ! && || [logical: not/and/or][where && and || return an operand, not necessarily a bool] << >> >>> >>= <<= >>>= [bitshift: left/right (signed)/right (unsigned)] % %= [C-style (truncated) modulo] %% %%= [floor modulo (e.g. R)] ?? ??= [PERHAPS][null-coalescing operator] ?. [PERHAPS][optional chaining operator] a blueprint for ideal operators (further): ? : [ternary operator]['c ? x : y', where c can be any value, not necessarily a bool] ?: [PERHAPS][would be equivalent to 'x ? x : y' and to 'x || y'] == [equals] != [not equal][PERHAPS: case-insensitive not equals (e.g. AutoHotkey)] <> [not equal][note: != and <> would both be present] < > <= >= [less than/greater than, less than or equal to/greater than or equal to] = [assign][PERHAPS: case-insensitive equals (e.g. AutoHotkey)] := [assign] ++ -- [increment/decrement] <=> [comparison (spaceship operator)] !== [PERHAPS] === [PERHAPS] => [fat-arrow function] .. [range (inclusive end)][PERHAPS] ..< [range (exclusive end)][PERHAPS] ~= [RegExMatch (e.g. AutoHotkey)][PERHAPS] non-operators: // [comments] /* */ [multi-line comments (and single-line comments)] ; [no role][PERHAPS: comments (e.g. AutoHotkey)] \ [escape character] ` [no role][PERHAPS: escape character (e.g. AutoHotkey)][PERHAPS: template literals (e.g. JavaScript)] :: [PERHAPS][hotkey/hotstring (e.g. AutoHotkey)] # [directives][JavaScript: class private fields] , [separate statements] [ ] [get object value (aka subscript)] { } [scope, define object, noop] ( ) [group] _ [often used as a variable name][numeric literal separator] " " [literal string] ' ' [literal string (but its use discouraged, prefer " ")] : [object property assignment, and part of ternary operators] also: spare binary operators that can be defined by 2-parameter functions: op_a to op_z [possible future operators (author's proposal), least worst option so far]
possible operators for C-style (truncated) integer division: i.e. the values (integers or floats) are divided as floats then truncated (towards 0) to the nearest integer: ~/ (and ~/=) (e.g. Dart) possible operators for floor division: i.e. the values (integers or floats) are divided as floats then floored (rounded down) to the nearest integer: // (and //=) is used by Python (but is often unavailable since it's used for comments) ~~/ (and ~~/=) (author's proposal) (the least worst option so far) _/ (and _/=) (author's proposal), but _ is often a variable name possible operators for true division: i.e. the values (integers or floats) are divided as floats, and a float is returned: / (i.e. ideally int/int would return a float, because it's more intuitive, but if int/int already returns an int, a new symbol is needed ...) /./ (author's proposal) (one of the least worst options so far) ../ (author's proposal) (one of the least worst options so far) (alternatively if int/int already returns an int, it could be prohibited, use ~/ if int/int is wanted) possible spare binary operators that can be defined by 2-parameter functions: i.e. if one programming language has an operator, and one doesn't, or if 2 languages use the same symbol, but the functionality differs, use a spare binary operator, and give it a function, and string replace the old operator with the spare operator, to preserve the code intact, instead of trying to refactor the code to use a custom binary function (which can create bugs): op_a to op_z (e.g. 'a % b' in language 1, 'a op_m b' in language 2)
'SymCommentMultDemo': Testing the following multi-line comment symbols: AutoHotkey: /* */ C++: /* */ C#: /* */ Crystal: [none] Excel: [none] Excel VBA: [none] Go: /* */ Java: /* */ JavaScript: /* */ Kotlin: /* */ PHP: /* */ Python: [none] R: [none] Ruby: =begin =end Rust: /* */ Scala: /* */ SQL (MySQL): /* */ SQL (PostgreSQL): /* */ SQL (SQLite): /* */ Swift: /* */ TESTS: note: for the tests below, use the language's multi-line comment symbols (e.g. /* */, =begin =end) note: try comments at the beginning, in the middle, and at the end, e.g.: /* */ print("hello") /* */ print("hello") /* */ see also: SymCommentMult TEST 1 (useful pattern to comment out the rest of the document): [worked: AutoHotkey/MySQL/SQLite] [failed: all other languages] /* comment TEST 2: [worked: AutoHotkey/MySQL/SQLite] [failed: all other languages] /* comment 1 /* comment 2 /* comment 3 TEST 3: [failed: all languages] */ TEST 4: [failed: all languages] */ */ */ TEST 5 (useful pattern for fixing/translating code one section at a time): [worked: all languages except Kotlin/PostgreSQL/Rust/Scala/Swift] [note: Kotlin: worked if at very bottom (with no trailing newline)] /* comment 1 /* comment 2 /* comment 3 */ TEST 6: [failed: all languages] [note: Kotlin: worked if at very bottom (with no trailing newline)] /* comment 1 /* comment 2 /* comment 3 */ */ TEST 7 (useful pattern for fixing/translating code one section at a time): [worked: all languages] [note: AutoHotkey: use: */ line break /*] [note: Ruby: use: =end line break =begin] [note: also worked with Python, replace /* with ''', and */ with '''] /* comment 1 */ /* comment 2 */ /* comment 3 */ /* comment 4 */