Programming Language Cheat Sheets: Operators and Symbols

Strings Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects New Features Timelines 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.

Introduction

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.

By Role

UFL: OpSpread: spread (splat) (for variadic function definitions/calls) AutoHotkey: * [e.g. MyFunc(oArray*)] C++: ... [note: ... (fold expressions) for function definitions *only*, no special syntax for function calls][also: macros: ... and __VA_ARGS__][also: va_list/va_start/va_arg/va_end (WARNING: this approach requires that a param, e.g. the first param, indicate how many params were passed)] C#: .. and params [e.g. MyFunc(..oArray)][note: 'params' keyword for function definitions, .. (2 dots) (spread operator) for function calls][WARNING: .. doesn't work universally in function calls] Crystal: * [e.g. MyFunc(*oTuple)] Excel: [none] Excel VBA: ParamArray [note: ParamArray for function definitions, no special syntax for function calls] Go: Java: ... [note: ... (varargs feature) for function definitions *only*, no special syntax for function calls][WARNING: 'varargs' (with 's') is name, '...' is syntax] JavaScript: ... [e.g. MyFunc(...oArray)][note: spread syntax] Kotlin: * and vararg [e.g. MyFunc(*oArray)][note: 'vararg' keyword for function definitions, * (spread operator) for function calls][WARNING: 'vararg' (no 's') is syntax] PHP: ... [e.g. MyFunc(...$oArray)] Python: * [e.g. MyFunc(*oArray)][note: splat] R: Ruby: * [e.g. MyFunc(*oArray)] Rust: [none] Swift: ... [note: ... for function definitions *only*, no special syntax for function calls][note: ... is also 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] AutoHotkey: c ? x : y C++: c ? x : y C#: c ? x : y [WARNING: c must be a bool] Crystal: c ? x : y [MAJOR WARNING: in Ruby, 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] Go: [none] Java: c ? x : y [WARNING: c must be a bool] JavaScript: c ? x : y Kotlin: if (c) x else y [WARNING: unusual operators][WARNING: 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 [WARNING: unusual operators, and operand order][note: can be used in expressions] 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][WARNING: c must be a bool][note: can be used in expressions][note: curly braces are needed] Swift: c ? x : y [WARNING: 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] AutoHotkey: || [note: AHK v2 onwards] C++: [none] C#: [none] Crystal: || [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: [none] Excel VBA: [none] Go: [none] [can use: cmp.Or(vVar1, vVar2, vVar3)][requires: import "cmp"] Java: [none] JavaScript: || Kotlin: [none] [can use: arrayOf(vVar1, vVar2, vVar3).find{it!=0} ?: 0] PHP: ?: Python: or R: Ruby: || [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: [none] Swift: [none] UFL: OpNullCoalescing: null-coalescing operator [x ?? y][equivalent to (x != null) ? x : y][if x is non-null, return x, else y] AutoHotkey: [none] C++: [none] C#: ?? Crystal: [none] [can use: (vVar != nil) ? vVar : vDefault][also (but with a confusing order): vVar.nil? ? vDefault : vVar][also: [vVar,vDefault].find{|v|v!=nil}] Excel: [none] Excel VBA: [none] Go: Java: [none] [can use: oOptional.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: vVar if (vVar is not None) else vDefault][also: next((v for v in [vVar] if v is not None), vDefault)] R: Ruby: [none] [can use: (vVar != nil) ? vVar : vDefault][also (but with a confusing order): vVar.nil? ? vDefault : vVar][also: [vVar,vDefault].find{|v|v!=nil}] Rust: [none] Swift: ?? [note: nil-coalescing operator][note: Swift uses nils rather than nulls] UFL: SymSep: statement separator (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] Go: Java: ; [note: statements must end with ;] JavaScript: ; Kotlin: ; PHP: ; [note: statements must end with ;] Python: ; R: Ruby: ; Rust: ; [note: statements must end with ;] Swift: ; UFL: SymEscape: string escape character [individual characters by frequency: nrt\'" abfv0 es$;?][see also: IntToStrCharEscapeDemo] AutoHotkey: ` [`a `b `f `n `r `s `t `v `` `' `" `;][note: AHK v1 used dual quoting for "] 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 \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"] 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 \' \" \\] 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 \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] Swift: \ [\n \r \t \' \" \\ \0][also (with further chars): \u] UFL: SymInterpolateDemo: string interpolation [see also: Format] AutoHotkey: [none] [can use: Format("Hello, {}!", name)] C++: [none] [can use: std::format("Hello, {}!", name)][requires: #include <format>][note: ' is used for chars] C#: $"Hello, {name}!" [note: ' is used for chars] Crystal: "Hello, #{name}!" [WARNING: # is a special character in string literals][note: ' is used for chars] Excel: [none] Excel VBA: [none] Go: [none] [can use: fmt.Sprintf("Hello, %v!", name)][note: ' is used for chars] Java: [none] [can use: String.format("Hello, %s!", name)][note: ' is used for chars] JavaScript: `Hello, ${name}!` Kotlin: "Hello, ${name}!" [also: "Hello, $name!"][WARNING: $ is a special character in string literals][note: ' 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] Python: f"Hello, {name}!" [also: f'Hello, {name}!'] R: [none] [can use: sprintf("Hello, %s!", name)] Ruby: "Hello, #{name}!" [WARNING: # is a special character in string literals][note: doesn't work with single quotes] Rust: [none] [can use: format!("Hello, {name}!")][note: ' is used for chars] Swift: "Hello, \(name)!" [note: ' is not used for strings or chars] UFL: OpPow: power (exponent) AutoHotkey: ** C++: [none] C#: [none] Crystal: ** Excel: ^ Excel VBA: ^ Go: Java: [none] JavaScript: ** Kotlin: [none] PHP: ** Python: ** R: Ruby: ** Rust: [none] Swift: [none] 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] Swift: // UFL: SymCommentMult: multi-line comments (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: Ruby: =begin =end [WARNING: only work at the start of a line] Rust: /* */ Swift: /* */ UFL: OpConcat: concatenate 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: 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: Ruby: + [WARNING: + for addition and concatenation] Rust: + [WARNING: + for addition and concatenation] Swift: + [WARNING: + for addition and concatenation] UFL: OpStrLT/OpStrGT: string comparison (less than/greater than) AutoHotkey: [none] [can use: StrCompare()] C++: < > [e.g. ((std::string)"abc" < (std::string)"def")][also (for char arrays): strcmp()] C#: [none] [can use: String.Compare()] Crystal: < > Excel: < > Excel VBA: < > Go: Java: [none] [can use: compareTo()] JavaScript: < > Kotlin: < > PHP: < > Python: < > R: Ruby: < > Rust: < > Swift: < > UFL: OpEquals: comparison (equality) AutoHotkey: == [case-insensitive: =] C++: == [e.g. ((std::string)"abc" == (std::string)"def")][also (for char arrays): strcmp()] C#: == Crystal: == Excel: = [case-insensitive] Excel VBA: = [case-sensitive (unlike Excel sheet formulae)] Go: Java: == JavaScript: == Kotlin: == [also (referential equality): ===] PHP: === [also (equal after type juggling): ==] Python: == R: Ruby: == [also: eql (type-sensitive), equal (compares object IDs)][e.g. 1.eql?(1.0)][e.g. [].equal?([])] Rust: == Swift: == UFL: OpNotEquals: comparison (not equals) AutoHotkey: !== [case-insensitive: !=] C++: != [e.g. ((std::string)"abc" != (std::string)"def")][also (for char arrays): strcmp()] C#: != Crystal: != Excel: <> Excel VBA: <> [case-sensitive (unlike Excel sheet formulae)] Go: Java: != JavaScript: !== [also: !=] Kotlin: != [also (referential equality negated counterpart): !==] PHP: !== [also (not equal after type juggling): != <>] Python: != R: Ruby: != Rust: != 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: Java: i++ ++i i+=1 JavaScript: i++ ++i i+=1 Kotlin: i++ ++i i+=1 PHP: $i++ ++$i $i+=1 Python: i+=1 R: Ruby: i+=1 Rust: i+=1 Swift: i+=1 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] [can use: BIN2DEC/OCT2DEC/HEX2DEC] Excel VBA: [none]/&O/&H [can use: WorksheetFunction.Bin2Dec][note: Visual Basic 2017 has &B] 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 Swift: 0b/0o/0x UFL: SymSepNum: numeric literal separator (digit separator) (break up long numbers) 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: _ Swift: _

By Symbol

UFL: (symbol): / (applied to integers) [C-style integer division: divide then round towards zero (truncate)][see also: TrueDiv] AutoHotkey: true division C++: C-style integer division [WARNING: not true division] C#: C-style integer division [WARNING: not true division] Crystal: true division Excel: true division Excel VBA: true division Go: Java: C-style integer division [WARNING: not true division] JavaScript: true division Kotlin: C-style integer division [WARNING: not true division] PHP: true division Python: true division [note: Python 1/2: floor division] R: Ruby: floor division [WARNING: not true division] Rust: C-style integer division [WARNING: not true division] Swift: C-style integer division [WARNING: not true division] UFL: (symbol): / (applied to floats) AutoHotkey: true division C++: true division C#: true division Crystal: true division Excel: true division Excel VBA: true division Go: Java: true division JavaScript: true division Kotlin: true division PHP: true division Python: true division R: Ruby: true division Rust: true division Swift: true division UFL: (symbol): // AutoHotkey: C-style integer division [note: in AHK v1: sometimes floor division] C++: comment C#: comment Crystal: floor division Excel: ___ Excel VBA: ___ Go: Java: comment JavaScript: comment Kotlin: comment PHP: comment Python: floor division R: Ruby: ___ Rust: comment Swift: comment UFL: (symbol): % AutoHotkey: ___ [can use: the Mod function (C-style modulo)] C++: C-style modulo C#: C-style modulo Crystal: floor modulo [WARNING: % as floor modulo is uncommon][WARNING: mathematical operator used on strings: % also performs sprintf] Excel: ___ [can use: the MOD function (floor modulo)][WARNING: Excel/Excel VBA differ] Excel VBA: ___ [can use: the 'Mod' operator (C-style modulo)][WARNING: Excel/Excel VBA differ] Go: Java: C-style modulo JavaScript: C-style modulo Kotlin: C-style modulo PHP: C-style modulo Python: floor modulo [WARNING: % as floor modulo is uncommon][WARNING: mathematical operator used on strings: % is also the string formatting operator] R: Ruby: floor modulo [WARNING: % as floor modulo is uncommon][WARNING: mathematical operator used on strings: % also performs sprintf] Rust: C-style modulo Swift: C-style modulo UFL: (symbol): ' AutoHotkey: literal strings 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 Swift: ___ UFL: (symbol): || (whether it returns a bool or an operand) (i.e. whether it's equivalent to a short-ternary operator) [note: examples are equivalent to JavaScript's: a || b || c] AutoHotkey: 0 || 123 [returns: 123][note: AHK v1: returns 1 (i.e. True)] C++: 0 || 123 [returns: 1 (i.e. True)][can use: a?a : b?b : c] C#: 0!=0 || 123!=0 [returns: True][can use: (a!=0) ? a : (b!=0) ? b : c] Crystal: 0 || 123 [returns: 0][MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: OR(0,123) [returns: TRUE] Excel VBA: 0 Or 123 [returns: 123] Go: Java: 0!=0 || 123!=0 [returns: true][can use: (a!=0) ? a : (b!=0) ? b : c] JavaScript: 0 || 123 [returns: 123] Kotlin: 0!=0 || 123!=0 [returns: 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][can use: if (a!=0) a else if (b!=0) b else c] PHP: 0 || 123 [returns: 1 (i.e. True)][note: '0 ?: 123' returns 123] Python: 0 or 123 [returns: 123] R: Ruby: 0 || 123 [returns: 0][MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: false || true [returns: true][WARNING: cannot use ints with ||] Swift: 0 != 0 || 123 != 0 [returns: true][note: '0 || 123' is invalid][can use: (a != 0) ? a : (b != 0) ? b : c] UFL: (symbol): ! (applied to integers e.g. !123) AutoHotkey: 0 C++: 0 C#: error [note: !true returns false] Crystal: false [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: error [WARNING: Excel lacks '!'][note: NOT(123) returns FALSE] Excel VBA: error [WARNING: 'Not' in Excel VBA is bitwise-not][note: (123 = 0) returns False] Go: Java: error [note: !true returns false] JavaScript: false Kotlin: error [note: !true returns false] PHP: false Python: error [WARNING: Python lacks '!'][note: not 123 returns False] R: Ruby: false [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: -124 [WARNING: '!' in Rust is bitwise-not][note: (123 == 0) returns false] Swift: error [note: !true returns false] UFL: (symbol): !! (applied to integers e.g. !!123) (i.e. apply ! twice) AutoHotkey: 1 C++: 1 C#: error [note: !!true returns true] Crystal: true [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Excel: error [WARNING: Excel lacks '!'][note: NOT(NOT(123)) returns TRUE] Excel VBA: error [WARNING: 'Not' in Excel VBA is bitwise-not][note: ((123 = 0) = False) returns True] Go: Java: error [note: !!true returns true] JavaScript: true Kotlin: error [note: !!true returns true] PHP: true Python: error [WARNING: Python lacks '!'][note: not not 123 returns True] R: Ruby: true [MAJOR WARNING: in Ruby, only false/nil are considered falsy (e.g. 0 and "" are considered truthy)] Rust: 123 [WARNING: '!' in Rust is bitwise-not][note: ((123 == 0) = false) returns true] Swift: error [note: !(!true) returns false][WARNING: error if attempt '!!': 'unary operators must not be juxtaposed'] UFL: (symbol): = AutoHotkey: equals [note: *case-insensitive* when comparing strings] C++: assign C#: assign Crystal: assign Excel: equals [note: *case-insensitive* when comparing strings] Excel VBA: assign [also: comparison (case-sensitive when comparing strings)] Go: Java: assign JavaScript: assign Kotlin: assign PHP: assign Python: assign R: Ruby: assign Rust: assign Swift: assign UFL: (symbol): == AutoHotkey: equals [note: case-sensitive when comparing strings] C++: equals C#: equals Crystal: equals Excel: ___ Excel VBA: ___ Go: 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: Ruby: equals Rust: equals Swift: equals UFL: (symbol): === AutoHotkey: ___ C++: ___ C#: ___ Crystal: case subsumption operator [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 [is right operand a member of left operand][e.g. used in case statements] Rust: ___ Swift: ___ UFL: (symbol): != AutoHotkey: not equal [note: *case-insensitive* when comparing strings] C++: not equal C#: not equal Crystal: not equal Excel: ___ Excel VBA: ___ Go: Java: not equal JavaScript: not equal Kotlin: not equal PHP: not equal after type juggling Python: not equal R: Ruby: not equal Rust: not equal Swift: not equal UFL: (symbol): !== 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: ___ Swift: ___ UFL: (symbol): <> AutoHotkey: ___ [deprecated: was available in 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: ___ Swift: ___

Operators Across Multiple Languages

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] ~ & | ^ [bitwise: not/and/or/xor][^ is sometimes power][Visual Basic: & is concatenate][C++: & is also address-of] ! && || [logical: not/and/or][logical not (logical negation)][Swift: unwrap optional][Rust: WARNING: ! is also bitwise-not (and used for macro expansion)] ? : [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)][note: in Excel, % is equivalent to '/100'] 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] role: operators (augmented assignment versions): += -= *= /= **= &= |= ^= >>= <<= >>>= .= %= ??= //= ~/= \= role: operators further: ~/ [C-style 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] . [member access][AutoHotkey/Perl/PHP: concatenate] ~= [AutoHotkey: RegExMatch] =~ [Ruby: RegEx match] !~ [Ruby: RegEx not match] :: [C++: scope qualifier][AutoHotkey: hotkey/hotstring][Kotlin: reference] # [directives] ::<> [Rust: turbofish operator (specify a type, e.g. '::<i32>'/'::<String>')] 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] _ [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] : [object property assignment e.g. {"myprop": 123}] ?. [optional chaining 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)] 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']

Operators and Symbols Listed in: The C Programming Language (1978)

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 '//')

The Universal Function Library Project: Details

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 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 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] , [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]

Inventing Operators

possible operators for C-style 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)