syntax
examples
languages
decimal literals
-123.45
(most languages)
scientific notation
1.23e-2
prefix hexadecimal
0xDEADBEEF
prefix binary
0b1110
prefix octal
0o777
unix-style octal
0777
C, JS (deprecated)
radix prefix
16rDEADBEEF
Smalltalk
syntax
examples
languages
single quote
'a string'
JS, Python, Ruby, Smalltalk
double quote
"a string"
JS, Python, Ruby*, Swift, Rust, Elixir*, Clojure
backtick
`a string`
JS*
sigils
%q(foo bar baz)
Ruby
...
%Q(foo bar baz)
Ruby*
...
~s(foo bar baz)
Elixir*
* - Allows interpolation
syntax
examples
languages
sigil only
$value
PHP, Dart
escaped expr
${value}
JS, PHP, Dart
...
#{value}
Ruby
...
$(value)
Julia
...
\(value)
Swift
syntax
examples
languages
backticks
`
line 1
line 2
`
JS*
EOL backslash
"line 1 \
line 2"
JS
triple quotes
"""
line 1
line 2
"""
Python*, Elixir*
heredoc
<<HEREDOC
line 1
line 2
HEREDOC
Ruby*
implicit concatenation
"line 1"
"line 2"
C, Python
* - Preserves newlines
syntax
examples
languages
single quote
'A'
Rust
question mark
?A
Elixir
backslash
\A
Clojure
syntax
examples
languages
Perl-style
/foo.+b[ar]$/
JS, Ruby
tagged string
r"foo.+b[ar]$"
Python, Julia
...
#"foo.+b[ar]$"
Clojure
sigil
~r/foo.+b[ar]$/
Elixir
Interned strings (symbols, keywords, etc)
syntax
examples
languages
colon
:foo
Ruby, Clojure, Elixir, Julia
single quote
'foo
Scheme, Clojure*, Scala
syntax
examples
languages
notes
char list
'a list of chars'
Elixir
linked list of chars used for backwards compatibility with older Erlang code
homogeneous
heterogeneous
by order
List
Tuple
by name
Dictionary
Record
syntax
examples
languages
parens
(foo, bar)
Elm, Python*, Julia, Rust, Swift
curly
{foo, bar}
Elixir
multiple return, but no tuple value type
return (foo, bar)
Go*
idiomatically uses lists
[foo, bar]
JS, Clojure, PHP, Ruby*
* - parens/brackets optional
alt. "vectors", "arrays"
syntax
examples
languages
brackets
[1, 2, 3]
JS, Ruby, Python, Elixir, Elm, Clojure*, PHP†
braces
{1, 2, 3}
Lua†, Java, C
tagged braces
[]int{1, 2, 3}
Go
macro
vec![1, 2, 3]
Rust
* - commas optional
† - syntactic sugar for dictionary with integer keys
syntax
examples
languages
subscript
x[1]
(most languages)
syntax
examples
languages
colon range
x[start:end]
Python, Go
subscript with range object
x[start..end]
Ruby
syntax
examples
languages
cons operator
first :: second :: rest
Elm
wrapped cons
[first, second | rest]
Elixir
spread
[first, second, ...rest]
JS
...
[first, second, *rest]
Ruby, Python
NOTE: 'spread' can go anywhere in list; 'wrapped cons' can only go in last position
syntax
examples
languages
notes
quoted sexpr
'(foo bar)
Clojure
used for representing syntax, not (normal) data
set
#{ 1 2 3 }
Clojure
set with type hint
var x : Set = [1,2,3]
Swift
array (not linked list)
[| 1, 2, 3 |]
Reason, OCaml
contiguous memory, O(1) lookup
byte array
<<1, 2, 3>>
Elixir
contiguous memory, O(1) lookup, bytes only
matrix
[1 2; 3 4]
Julia
multidimensional array
alt. structs
syntax
examples
languages
tagged
Point{ x: 123, y: 456 }
Rust, Go
positional
point p = { 123, 456 }
C
designated initializer
{ .x = 123, .y = 456 }
C
extensible records
{ x = 123, y = 456 }
Elm
constructor function
Point(x: 123, y: 456)
Swift, Ruby
idiomatically uses dicts
JS, Python, Clojure, Elixir
syntax
examples
languages
dots
point.x
C, Go, Rust, Swift, JS, Ruby, Elm, Elixir
dict lookup only
Python, Clojure
alt. map, hash, associative array, table
syntax
examples
languages
braces
{"x": 123, "y": 456}
JS, Python
braces + bare
{x: 123, y: 456}
JS, Ruby
braces + equals
{x=123, y=456}
Lua
braces + arrow
{:x => 123, :y => 456}
Ruby
...
%{:x => 123, :y => 456}
Elixir
braces + alternate kv
{:x 123 :y 456}
Clojure
square + arrow
["x" => 123, "y" => 456]
PHP
square + colon
["x": 123, "y": 456]
Swift
syntax
examples
languages
subscript
x[key]
JS, Python, Ruby, Lua, Elixir, PHP, Swift
syntax
examples
languages
same as list
{ ...rest }
JS
double-splat
{ **rest }
Ruby, Python
Other key-value structures
[x: 123, y: 456]
= [{:x, 123}, {:y, 456}]
lookup is O(n)
Typed structures (e.g. classes, enums, variants)
Comments