diff --git a/Introduction.ipynb b/Introduction.ipynb
index ff65320..2710d3b 100644
--- a/Introduction.ipynb
+++ b/Introduction.ipynb
@@ -302,7 +302,7 @@
},
{
"cell_type": "code",
- "execution_count": 19,
+ "execution_count": 1,
"metadata": {
"collapsed": false
},
@@ -310,21 +310,21 @@
{
"data": {
"text/plain": [
- "Rational{Int64}"
+ "true"
]
},
- "execution_count": 19,
+ "execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "typeof(ans)"
+ "12 ≠ 42"
]
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 3,
"metadata": {
"collapsed": false
},
@@ -332,21 +332,21 @@
{
"data": {
"text/plain": [
- "\"Like in perl you may write x=7\""
+ "false"
]
},
- "execution_count": 20,
+ "execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "\"Like in perl you may write x=$x\""
+ "2 ∈ [6,3,5]"
]
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 19,
"metadata": {
"collapsed": false
},
@@ -354,44 +354,21 @@
{
"data": {
"text/plain": [
- "\"... but also 1096.6331584284585\""
+ "Rational{Int64}"
]
},
- "execution_count": 21,
+ "execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "\"... but also $(exp(x))\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Type Hierarchy "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "The type hierarchy for numbers looks like:\n",
- ""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Functions + Multiple Dispatch\n",
- "One can define functions simply like that:"
+ "typeof(ans)"
]
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 20,
"metadata": {
"collapsed": false
},
@@ -399,98 +376,66 @@
{
"data": {
"text/plain": [
- "f (generic function with 1 method)"
+ "\"Like in perl you may write x=7\""
]
},
- "execution_count": 22,
+ "execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "f(x) = x ^ 3"
+ "\"Like in perl you may write x=$x\""
]
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
- "text/html": [
- "1 method for generic function
f:
"
- ],
"text/plain": [
- "# 1 method for generic function \"f\":\n",
- "f(x) at In[22]:1"
+ "\"... but also 1096.6331584284585\""
]
},
- "execution_count": 23,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "methods(f)"
+ "\"... but also $(exp(x))\""
]
},
{
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "27"
- ]
- },
- "execution_count": 24,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "cell_type": "markdown",
+ "metadata": {},
"source": [
- "f(3)"
+ "# Type Hierarchy "
]
},
{
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "\"ha ha ha \""
- ]
- },
- "execution_count": 25,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "cell_type": "markdown",
+ "metadata": {},
"source": [
- "f(\"ha \")"
+ "The type hierarchy for numbers looks like:\n",
+ ""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "An equivalent syntax used for more complicated function is:"
+ "# Functions + Multiple Dispatch\n",
+ "One can define functions simply like that:"
]
},
{
"cell_type": "code",
- "execution_count": 26,
+ "execution_count": 6,
"metadata": {
"collapsed": false
},
@@ -498,53 +443,43 @@
{
"data": {
"text/plain": [
- "g (generic function with 1 method)"
+ "f (generic function with 2 methods)"
]
},
- "execution_count": 26,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "function g(y)\n",
- " println(\"in function g\")\n",
- " y+3\n",
- "end"
+ "f(x) = x ^ 3"
]
},
{
"cell_type": "code",
- "execution_count": 27,
+ "execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "in function g\n"
- ]
- },
{
"data": {
"text/plain": [
- "6"
+ "27"
]
},
- "execution_count": 27,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "g(3)"
+ "f(3)"
]
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 8,
"metadata": {
"collapsed": false
},
@@ -553,150 +488,106 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "in function g\n"
+ "now in f(x::AbstractString)\n"
]
},
- {
- "ename": "LoadError",
- "evalue": "LoadError: MethodError: `+` has no method matching +(::ASCIIString, ::Int64)\nClosest candidates are:\n +(::Any, ::Any, !Matched::Any, !Matched::Any...)\n +(!Matched::Int64, ::Int64)\n +(!Matched::Complex{Bool}, ::Real)\n ...\nwhile loading In[28], in expression starting on line 1",
- "output_type": "error",
- "traceback": [
- "LoadError: MethodError: `+` has no method matching +(::ASCIIString, ::Int64)\nClosest candidates are:\n +(::Any, ::Any, !Matched::Any, !Matched::Any...)\n +(!Matched::Int64, ::Int64)\n +(!Matched::Complex{Bool}, ::Real)\n ...\nwhile loading In[28], in expression starting on line 1",
- "",
- " in g at ./In[26]:3"
- ]
- }
- ],
- "source": [
- "g(\"bla \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
{
"data": {
"text/plain": [
- "g (generic function with 4 methods)"
+ "\"Hello\""
]
},
- "execution_count": 29,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "function g(y::Int)\n",
- " println(\"in function g(y::Int)\")\n",
- " y+1\n",
- "end\n",
- "\n",
- "function g(y::AbstractString, z=15)\n",
- " println(\"in function g(y::AbstractString)\")\n",
- " y * \"+$z\"\n",
- "end"
+ "f(\"ha \")"
]
},
{
"cell_type": "code",
- "execution_count": 30,
+ "execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "typeof(x) = Int64\n",
- "in function g(y::Int)\n"
+ "ename": "LoadError",
+ "evalue": "LoadError: UndefVarError: Float not defined\nwhile loading In[15], in expression starting on line 1",
+ "output_type": "error",
+ "traceback": [
+ "LoadError: UndefVarError: Float not defined\nwhile loading In[15], in expression starting on line 1",
+ ""
]
- },
- {
- "data": {
- "text/plain": [
- "3"
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
}
],
"source": [
- "x=2\n",
- "@show typeof(x)\n",
- "g(x)"
+ "super(Float)"
]
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "ASCIIString\n",
- "in function g(y::AbstractString)\n"
- ]
- },
{
"data": {
"text/plain": [
- "\"bla+15\""
+ "f (generic function with 3 methods)"
]
},
- "execution_count": 31,
+ "execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "x=\"bla\"\n",
- "println(typeof(x))\n",
- "g(x)"
+ "function f(x::AbstractString) \n",
+ " println(\"\\nnow in f(x::AbstractString) with x=$x of type $(typeof(x))\")\n",
+ " \"Hello $x\"\n",
+ "end\n",
+ "\n",
+ "function f(x::AbstractFloat) \n",
+ " println(\"\\nnow in f(x::AbstractFloat) with x=$x of type $(typeof(x))\")\n",
+ " x+1.0\n",
+ "end"
]
},
{
"cell_type": "code",
- "execution_count": 32,
+ "execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "in function g(y::AbstractString)\n"
- ]
- },
{
"data": {
+ "text/html": [
+ "3 methods for generic function
f:
- f(x::AbstractString) at In[28]:2
- f(x::AbstractFloat) at In[28]:7
- f(x) at In[6]:1
"
+ ],
"text/plain": [
- "\"bla+1000\""
+ "# 3 methods for generic function \"f\":\n",
+ "f(x::AbstractString) at In[28]:2\n",
+ "f(x::AbstractFloat) at In[28]:7\n",
+ "f(x) at In[6]:1"
]
},
- "execution_count": 32,
+ "execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "g(x,1000)"
+ "methods(f)"
]
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 32,
"metadata": {
"collapsed": false
},
@@ -705,26 +596,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "UTF8String\n",
- "in function g(y::AbstractString)\n"
+ "\n",
+ "now in f(x::AbstractFloat) with x=2.5 of type Float64\n",
+ "f(2.5) = 3.5\n"
]
- },
- {
- "data": {
- "text/plain": [
- "\"λ+15\""
- ]
- },
- "execution_count": 33,
- "metadata": {},
- "output_type": "execute_result"
}
],
"source": [
- "x=\"λ\"\n",
- "α = 7\n",
- "println(typeof(x))\n",
- "g(x)"
+ "@show f(2.5);"
]
},
{
@@ -735,18 +614,17 @@
},
"outputs": [
{
- "data": {
- "text/plain": [
- "π = 3.1415926535897..."
- ]
- },
- "execution_count": 34,
- "metadata": {},
- "output_type": "execute_result"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "now in f(x::AbstractFloat) with x=2.5 of type Float16\n",
+ "f(Float16(2.5)) = 3.5\n"
+ ]
}
],
"source": [
- "π"
+ "@show f(Float16(2.5));"
]
},
{
@@ -755,88 +633,23 @@
"metadata": {
"collapsed": false
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "AbstractString"
- ]
- },
- "execution_count": 35,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "super(typeof(x))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 36,
- "metadata": {
- "collapsed": false
- },
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Float64\n",
- "in function g\n"
+ "\n",
+ "now in f(x::AbstractString) with x=abc of type ASCIIString\n",
+ "f(\"abc\") = \"Hello abc\"\n",
+ "\n",
+ "now in f(x::AbstractString) with x=αβγ of type UTF8String\n",
+ "f(\"αβγ\") = \"Hello αβγ\"\n"
]
- },
- {
- "data": {
- "text/plain": [
- "5.7"
- ]
- },
- "execution_count": 36,
- "metadata": {},
- "output_type": "execute_result"
}
],
"source": [
- "x=2.7\n",
- "println(typeof(x))\n",
- "g(x)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Multiple Dispatch"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 37,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "4 methods for generic function
g:
- g(y::Int64) at In[29]:2
- g(y::AbstractString) at In[29]:7
- g(y::AbstractString, z) at In[29]:7
- g(y) at In[26]:2
"
- ],
- "text/plain": [
- "# 4 methods for generic function \"g\":\n",
- "g(y::Int64) at In[29]:2\n",
- "g(y::AbstractString) at In[29]:7\n",
- "g(y::AbstractString, z) at In[29]:7\n",
- "g(y) at In[26]:2"
- ]
- },
- "execution_count": 37,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "methods(g)"
+ "@show f(\"abc\")\n",
+ "@show f(\"αβγ\");"
]
},
{
@@ -882,6 +695,33 @@
"methods(print)"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "2 methods for generic function
println:
"
+ ],
+ "text/plain": [
+ "# 2 methods for generic function \"println\":\n",
+ "println(io::IO, xs...) at strings/io.jl:25\n",
+ "println(xs...) at strings/io.jl:28"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "methods(println)"
+ ]
+ },
{
"cell_type": "markdown",
"metadata": {},
@@ -1191,7 +1031,7 @@
},
{
"cell_type": "code",
- "execution_count": 51,
+ "execution_count": 37,
"metadata": {
"collapsed": false
},
@@ -1205,7 +1045,7 @@
" 9"
]
},
- "execution_count": 51,
+ "execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
@@ -1216,7 +1056,7 @@
},
{
"cell_type": "code",
- "execution_count": 52,
+ "execution_count": 38,
"metadata": {
"collapsed": false
},
@@ -1224,24 +1064,24 @@
{
"data": {
"text/plain": [
- "3-element Array{Int64,1}:\n",
- " 3\n",
- " 4\n",
- " 11"
+ "3-element Array{Float64,1}:\n",
+ " 3.1\n",
+ " 4.1\n",
+ " 11.1"
]
},
- "execution_count": 52,
+ "execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "A+2"
+ "A+2.1"
]
},
{
"cell_type": "code",
- "execution_count": 53,
+ "execution_count": 41,
"metadata": {
"collapsed": false
},
@@ -1255,7 +1095,7 @@
" false"
]
},
- "execution_count": 53,
+ "execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
@@ -1266,7 +1106,7 @@
},
{
"cell_type": "code",
- "execution_count": 54,
+ "execution_count": 42,
"metadata": {
"collapsed": false
},
@@ -1280,7 +1120,7 @@
" 6 2 1"
]
},
- "execution_count": 54,
+ "execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
@@ -1291,7 +1131,7 @@
},
{
"cell_type": "code",
- "execution_count": 55,
+ "execution_count": 43,
"metadata": {
"collapsed": false
},
@@ -1305,7 +1145,7 @@
" 3 6 9 12"
]
},
- "execution_count": 55,
+ "execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}