Variables, Unicode & Basic Types

Naming conventions: variables & functions lowercase or snake_case; types and modules CamelCase; functions that modify arguments end with !

4.1 Variables

Naming conventions: variables & functions lowercase or snake_case; types and modules CamelCase; functions that modify arguments end with ! (sort!).

x = 10
name = "Julia"
δ = 0.001               # Unicode names: type \delta<Tab>
x₁ = 1                  # subscripts: x\_1<Tab>
😺 = "cat"              # emoji allowed
const SPEED_OF_LIGHT = 299_792_458   # constant (type must not change)
a, b = 1, 2             # multiple assignment (tuple destructuring)
a, b = b, a             # swap

4.2 Basic types

Int64 (Int) 42 (Int32 on 32-bit systems) 3.14, 1e-3, Inf, NaN true, false

'a', 'α' (32-bit Unicode code point) "hello" (UTF-8) nothing (no value) missing (statistical missing value) BigInt, BigFloat

UInt8 ... UInt128, Int8 ... Int128, Float16

typeof(42)          # Int64
typeof(3.0)         # Float64
typeof('a')         # Char
typeof(:sym)        # Symbol
typeof(1//2)        # Rational{Int64}
isa(1, Integer)     # true
1 isa Number        # true
sizeof(Int64)       # 8
typemax(Int64), typemin(Int8), eps(Float64)

4.3 Conversion & parsing

Float64(3)            # 3.0
Int(3.0)              # 3  (InexactError for 3.5)
round(Int, 3.7)       # 4
trunc(Int, 3.7)       # 3
floor(Int, -2.5), ceil(Int, 2.1)
convert(Float64, 2)   # 2.0
parse(Int, "42")      # 42
parse(Float64, "3.14")
tryparse(Int, "abc")  # nothing
string(42)            # "42"
Char(65), Int('A')    # 'A', 65