1  Introduction

1.1 Hello World

println() print to newline.

println("Hello, World")
#> Hello, World

1.2 Assign Variable

Dynamic typing

my_int = 10
#> 10
typeof(my_int)
#> Int64
my_pi = 3.1416
#> 3.1416
typeof(my_pi)
#> Float64
😸 = "smily cat"
#> "smily cat"
typeof(😸)
#> String

Sting interpolation with $

"This is $😸"
#> "This is smily cat"
😀 = 1
😞 = -1
🤐 = 0
🤐 == 😀 + 😞
#> true

1.3 Comment

# This is comment
#=

This 
is 
Multiline Comment

=#

1.4 Basic Math

1 + 1
#> 2
1 - 1
#> 0
2 * 3
#> 6
3 / 2
#> 1.5

like R

10 ^ 2
#> 100

like Python

5 % 2
#> 1

1.5 Operator

Operators Docs

Boolean Operators

!true
#> false
false && true
#> false
false || true
#> true

Logical Operator ignore type

1 == 1.0
#> true

1.6 Vectorized “dot” operators

[1,2,3] ^ 3 
# This would Error
[1,2,3] .^ 3
#> 3-element Vector{Int64}:
#>   1
#>   8
#>  27

a .^ b is parsed as the “dot” call (^).(a,b), which performs a broadcast operation:

  • combine arrays and scalars,
  • arrays of the same size (performing the operation elementwise)
  • even arrays of different shapes (e.g. combining row and column vectors to produce a matrix).

1.7 Exercise

convert() function

days = 365
days_float = convert(Float64, days) # Convert to Float64
#> 365.0
days == days_float 
#> true
@assert days == 365
@assert days_float == 365.0
convert(Int64, "1") # Error
parse(Int64, "1")
#> 1