In [1]:
1 + 2.0
Out[1]:
3.0
In [39]:
typeof(3.3)
Out[39]:
Float64
In [8]:
println("Hello World")
println("1 + 2 is: $(1 + 2)")
Hello World
1 + 2 is: 3
In [17]:
'a'
'\u2603'
Out[17]:
'☃'
In [15]:
int('☃')
Out[15]:
"2603"
In [26]:
['a' 'b' 'c']
Out[26]:
1x3 Array{Char,2}:
 'a'  'b'  'c'
In [20]:
['a' 'b' 'c';
'd' 'e' 'f';]
Out[20]:
2x3 Array{Char,2}:
 'a'  'b'  'c'
 'd'  'e'  'f'
In [27]:
[1, 2, 3]
Out[27]:
3-element Array{Int64,1}:
 1
 2
 3
In [33]:
Dict(:erik => "python",
     :justin => "ruby",
     :colin => "scala",
)
Out[33]:
Dict{Symbol,ASCIIString} with 3 entries:
  :erik   => "python"
  :colin  => "scala"
  :justin => "ruby"
In [34]:
a = 7
Out[34]:
7
In [35]:
erik = :erik
Out[35]:
:erik
In [37]:
erik::Symbol
Out[37]:
:erik
In [38]:
erik::Array
type: typeassert: expected Array{T,N}, got Symbol
while loading In[38], in expression starting on line 1
In [40]:
a = 3
if a > 4
    println("a is too big")
else
    println("a is $a")
end
a is 3
In [52]:
x = 1 == 2 ? "yeah!" : "nope..."
Out[52]:
"nope..."
In [48]:
for x = 1:3:10
    println(x)
end
1
4
7
10
In [47]:
o_count = 0
for x = "one two three"
    if x == 'o'
        o_count += 1
    end
end
o_count
Out[47]:
2
In [2]:
[x^2 for x = 1:5]
Out[2]:
5-element Array{Int64,1}:
  1
  4
  9
 16
 25
In [3]:
["$x $y" for x = 1:3, y='a':'c']
Out[3]:
3x3 Array{Union(UTF8String,ASCIIString),2}:
 "1 a"  "1 b"  "1 c"
 "2 a"  "2 b"  "2 c"
 "3 a"  "3 b"  "3 c"

Functions

In [60]:
function minimum(l)
    min = l[1]
    for x = l[2:end]
        min = min < x ? min : x
    end
    min
end
minimum([2, -3, 6, -4, 3])
Out[60]:
-4
In [61]:
f(x) = 2x
f(3)
Out[61]:
6
In [63]:
((x, y) -> x + y)(2, 3)
Out[63]:
5
In [76]:
map(c -> c + 2, "Hello")
Out[76]:
"Jgnnq"
In [70]:
filter(x -> x % 3 == 0, 1:10)
Out[70]:
3-element Array{Int64,1}:
 3
 6
 9

In the Next Section

  • Modules and imports
  • User Defined Types
  • Multiple Dispatch
  • Testing
  • External Libraries & Packaging
  • Simulations and Data Visualization