summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2016-03-04 15:56:47 -0700
committerkballou <kballou@devnulllabs.io>2016-03-07 15:31:22 -0700
commit3c20dbbdf4ca14fab918576a1479c7aa90196e6e (patch)
tree83be80fb18b20c3440d3e87f8739c6d1780b4223
parentbc484b7444ff68494b2da7b16ceefb0b1e4a396c (diff)
downloadfunc-w-elixir-3c20dbbdf4ca14fab918576a1479c7aa90196e6e.tar.gz
func-w-elixir-3c20dbbdf4ca14fab918576a1479c7aa90196e6e.tar.xz
Add code examples to presentation
-rw-r--r--src/code/1/atoms17
-rw-r--r--src/code/1/binaries13
-rw-r--r--src/code/1/booleans19
-rw-r--r--src/code/1/functions14
-rw-r--r--src/code/1/iex5
-rw-r--r--src/code/1/lists21
-rw-r--r--src/code/1/maps23
-rw-r--r--src/code/1/numbers29
-rw-r--r--src/code/1/patterns52
-rw-r--r--src/code/1/tuples17
-rw-r--r--src/code/2/fib_itr.exs15
-rw-r--r--src/code/2/fib_perf.out9
-rw-r--r--src/code/2/fib_rec.exs7
-rw-r--r--src/code/2/my_map.exs8
-rw-r--r--src/code/2/my_map.out2
-rw-r--r--src/code/2/my_map_red.exs17
-rw-r--r--src/code/2/my_map_red.out3
-rw-r--r--src/code/2/my_red.exs10
-rw-r--r--src/code/2/my_red.out2
-rw-r--r--src/code/2/qs.exs10
-rw-r--r--src/code/2/qs.out4
-rw-r--r--src/code/2/wc.exs28
-rw-r--r--src/code/2/wc.out6
-rw-r--r--src/func-w-elixir.tex341
-rw-r--r--src/references.bib14
25 files changed, 680 insertions, 6 deletions
diff --git a/src/code/1/atoms b/src/code/1/atoms
new file mode 100644
index 0000000..fe6b2b8
--- /dev/null
+++ b/src/code/1/atoms
@@ -0,0 +1,17 @@
+iex> :atom
+:atom
+iex> :ok
+:ok
+iex> :error
+:error
+iex> Foobar
+Foobar
+iex> :this_is_a_long_atom_dont_do_this
+:this_is_a_long_atom_dont_do_this
+
+iex> Atom.to_string :foo
+"foo"
+iex> String.to_atom "foo"
+:foo
+iex> String.to_atom "foo with a space and bar"
+:"foo with a space and bar"
diff --git a/src/code/1/binaries b/src/code/1/binaries
new file mode 100644
index 0000000..1ac8fbf
--- /dev/null
+++ b/src/code/1/binaries
@@ -0,0 +1,13 @@
+iex> <<1, 2, 3>>
+<<1, 2, 3>>
+iex> <<255, 255, 256>>
+<<255, 255, 0>>
+iex> <<256 :: size(16)>>
+<<1, 0>>
+iex> <<"Hello, 世界" :: utf8>>
+"Hello, 世界"
+
+iex> <<1, 2>> <> <<3>>
+<<1, 2, 3>>
+iex> "Hello, " <> "World"
+"Hello, World"
diff --git a/src/code/1/booleans b/src/code/1/booleans
new file mode 100644
index 0000000..6540097
--- /dev/null
+++ b/src/code/1/booleans
@@ -0,0 +1,19 @@
+iex> true
+true
+iex> false
+false
+iex> not false
+true
+
+iex> true or false
+true
+iex> true and false
+false
+iex> false || 13
+13
+iex> true && 42
+42
+iex> true == true
+true
+iex> true != false
+true
diff --git a/src/code/1/functions b/src/code/1/functions
new file mode 100644
index 0000000..03559ad
--- /dev/null
+++ b/src/code/1/functions
@@ -0,0 +1,14 @@
+iex> f = fn(x) -> x * x end
+#Function<6.54118792/1 in :erl_eval.expr/5>
+iex> f.(2)
+4
+iex> g = &(&1 * &1)
+#Function<6.54118792/1 in :erl_eval.expr/5>
+iex> h = fn(x) -> x + 1 end
+#Function<6.54118792/1 in :erl_eval.expr/5>
+iex> f.(2)
+4
+iex> g.(2)
+4
+iex> h.(1)
+2
diff --git a/src/code/1/iex b/src/code/1/iex
new file mode 100644
index 0000000..bd800a2
--- /dev/null
+++ b/src/code/1/iex
@@ -0,0 +1,5 @@
+Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
+
+Interactive Elixir (1.2.3) - press Ctrl+C to exit (type h() ENTER for help)
+
+iex(1)>
diff --git a/src/code/1/lists b/src/code/1/lists
new file mode 100644
index 0000000..836d30b
--- /dev/null
+++ b/src/code/1/lists
@@ -0,0 +1,21 @@
+iex> []
+[]
+iex> [1, 2, 3,]
+[1, 2, 3]
+iex> [1, :a, ['b']]
+[1, :a, ['b']]
+iex> [104, 101, 108, 108, 111]
+'hello'
+iex> 'hełło'
+'hełło'
+iex> 'こにちは、世界'
+[12371, 12395, 12385, 12399, 12289, 19990, 30028]
+
+iex> hd([1, 2, 3,])
+1
+iex> tl([1, 2, 3])
+[2, 3]
+iex> [1] ++ [2, 3]
+[1, 2, 3]
+iex> [1, 2, 3] -- [1]
+[2, 3]
diff --git a/src/code/1/maps b/src/code/1/maps
new file mode 100644
index 0000000..224af0e
--- /dev/null
+++ b/src/code/1/maps
@@ -0,0 +1,23 @@
+iex> %{}
+%{}
+iex> %{"key" => "value"}
+%{"key" => "value"}
+iex> %{a: 2, b: 1}
+%{a: 2, b: 1}
+iex> [{:a, 2}, {:b, 1}]
+[a: 2, b: 1]
+iex> [a: 2, b: 1]
+[a: 2, b: 1]
+
+iex> my_map = %{a: 2, b: 1}
+%{a: 2, b: 1}
+iex> my_map[:a]
+2
+iex> Map.get(my_map, :a)
+2
+iex> my_map.a
+2
+iex> Map.put(my_map, :c, 4)
+%{a: 2, b: 1, c: 4}
+iex> Map.put(my_map, :a, 42)
+%{a: 42, b: 1}
diff --git a/src/code/1/numbers b/src/code/1/numbers
new file mode 100644
index 0000000..9489e00
--- /dev/null
+++ b/src/code/1/numbers
@@ -0,0 +1,29 @@
+iex(1)> 42
+42
+iex(2)> -42
+-42
+iex(3)> 0
+0
+iex(4)> 1.0
+1.0
+iex(5)> 6.674e-11
+6.674e-11
+iex(6)> 0b1010
+10
+iex(7)> 0o755
+493
+iex(8)> 0xFF
+255
+
+iex> 0 + 1
+1
+iex> 6 * 7
+42
+iex> 2 - 4
+-2
+iex> 1/3
+0.3333333333333333
+iex> div(1, 3)
+0
+iex> rem(1, 3)
+1
diff --git a/src/code/1/patterns b/src/code/1/patterns
new file mode 100644
index 0000000..b93fdc4
--- /dev/null
+++ b/src/code/1/patterns
@@ -0,0 +1,52 @@
+iex> x = 1
+1
+iex> 1 = x
+1
+iex> x = 2
+2
+iex> 1 = x
+** (MatchError) no match of right hand side value: 2
+
+iex> [a, b, c] = [1, 2, 3]
+[1, 2, 3]
+iex> a
+1
+iex> b
+2
+iex> c
+3
+iex> [1, _, c] = [1, 2, 3]
+[1, 2, 3]
+iex> [2, _, d] = [1, 2, 3]
+** (MatchError) no match of right hand side value: [1, 2, 3]
+
+iex> [h|t] = [1, 2, 3]
+[1, 2, 3]
+iex> h
+1
+iex> t
+[2, 3]
+
+iex> %{a: 1} = %{a: 1, b: 2, c: 3}
+%{a: 1, b: 2, c: 3}
+iex> %{} = %{a: 3}
+%{a: 3}
+
+defmodule Foobar do
+ def sum_list([]), do: 0
+ def sum_list([h|t]), do: h + sum_list(t)
+end
+
+iex> Foobar.sum_list [1, 2, 3, 4, 5]
+15
+
+iex> << sign :: size(1), exp :: size(11), mantissa :: size(52)>> = <<3.14159 :: float>>
+<<64, 9, 249, 240, 27, 134, 110>>
+iex> sign
+0
+iex> exp
+1024
+iex> mantissa
+2570632149304942
+iex> :math.pow(-1, sign) * (1 + mantissa / :math.pow(2, 52)) * :math.pow(2, exp - 1023)
+3.14159
diff --git a/src/code/1/tuples b/src/code/1/tuples
new file mode 100644
index 0000000..60c5d52
--- /dev/null
+++ b/src/code/1/tuples
@@ -0,0 +1,17 @@
+iex> {}
+{}
+iex> {1, 2, 3}
+{1, 2, 3}
+iex> {1, :a, 3}
+{1, :a, 3}
+
+iex> tuple_size {1, 2, 3}
+3
+iex> elem({1, 2, 3}, 1)
+2
+iex> tuple = {:ok, 'hello'}
+{:ok, 'hello'}
+iex> put_elem(tuple, 1, 'world'}
+{:ok, 'world'}
+iex> tuple
+{:ok, 'hello'}
diff --git a/src/code/2/fib_itr.exs b/src/code/2/fib_itr.exs
new file mode 100644
index 0000000..2eafcee
--- /dev/null
+++ b/src/code/2/fib_itr.exs
@@ -0,0 +1,15 @@
+defmodule Fib do
+ def seq(0), do: 0
+ def seq(1), do: 1
+ def seq(n) when n > 1, do: compute_seq(n, 1, [0, 1])
+
+ defp compute_seq(n, i, acc) when n == i do
+ Enum.at(acc, length(acc) - 1)
+ end
+ defp compute_seq(n, i, acc) do
+ len = length(acc)
+ compute_seq(n, i + 1, acc++[Enum.at(acc, len-1) + Enum.at(acc, len-2)])
+ end
+end
+
+IO.puts Fib.seq(50)
diff --git a/src/code/2/fib_perf.out b/src/code/2/fib_perf.out
new file mode 100644
index 0000000..dda3a70
--- /dev/null
+++ b/src/code/2/fib_perf.out
@@ -0,0 +1,9 @@
+% /usr/bin/time elixir fib_rec.exs
+12586269025
+603.66user 0.08system 10:04.26elapsed 99%CPU (0avgtext+0avgdata 32892maxresident)k
+2856inputs+0outputs (0major+6861minor)pagefaults 0swaps
+
+% /usr/bin/time elixir fib_itr.exs
+12586269025
+0.24user 0.06system 0:00.28elapsed 110%CPU (0avgtext+0avgdata 33916maxresident)k
+0inputs+0outputs (0major+7617minor)pagefaults 0swaps
diff --git a/src/code/2/fib_rec.exs b/src/code/2/fib_rec.exs
new file mode 100644
index 0000000..edd3af8
--- /dev/null
+++ b/src/code/2/fib_rec.exs
@@ -0,0 +1,7 @@
+defmodule Fib do
+ def seq(0), do: 0
+ def seq(1), do: 1
+ def seq(n) when n > 1, do: seq(n-1) + seq(n-2)
+end
+
+IO.puts Fib.seq(50)
diff --git a/src/code/2/my_map.exs b/src/code/2/my_map.exs
new file mode 100644
index 0000000..ef219ef
--- /dev/null
+++ b/src/code/2/my_map.exs
@@ -0,0 +1,8 @@
+defmodule MyMap do
+ def map([], _), do: []
+ def map([h|t], f) do
+ [f.(h)] ++ map(t, f)
+ end
+end
+
+[1, 2, 3, 4, 5] |> MyMap.map(fn(x) -> x * 2 end) |> IO.inspect
diff --git a/src/code/2/my_map.out b/src/code/2/my_map.out
new file mode 100644
index 0000000..1781de0
--- /dev/null
+++ b/src/code/2/my_map.out
@@ -0,0 +1,2 @@
+% elixir my_map.exs
+[2, 4, 6, 8, 10]
diff --git a/src/code/2/my_map_red.exs b/src/code/2/my_map_red.exs
new file mode 100644
index 0000000..51f47f8
--- /dev/null
+++ b/src/code/2/my_map_red.exs
@@ -0,0 +1,17 @@
+defmodule MapReduce do
+ def reduce([], acc, _), do: acc
+ def reduce([h|t], acc, f) do
+ reduce(t, f.(h, acc), f)
+ end
+
+ def map([], _), do: []
+ def map(l, f) do
+ reduce(l, [], fn(x, acc) -> acc ++ [f.(x)] end)
+ end
+end
+
+[1, 2, 3, 4, 5]
+|> MapReduce.map(fn(x) -> x * 2 end)
+|> IO.inspect
+|> MapReduce.reduce(0, fn(x, acc) -> acc + x end)
+|> IO.inspect
diff --git a/src/code/2/my_map_red.out b/src/code/2/my_map_red.out
new file mode 100644
index 0000000..1a38a74
--- /dev/null
+++ b/src/code/2/my_map_red.out
@@ -0,0 +1,3 @@
+% elixir my_map_red.exs
+[2, 4, 6, 8, 10]
+30
diff --git a/src/code/2/my_red.exs b/src/code/2/my_red.exs
new file mode 100644
index 0000000..6966f3e
--- /dev/null
+++ b/src/code/2/my_red.exs
@@ -0,0 +1,10 @@
+defmodule MyReduce do
+ def reduce([], acc, _), do: acc
+ def reduce([h|t], acc, f) do
+ reduce(t, f.(h, acc), f)
+ end
+end
+
+[1, 2, 3, 4, 5] |>
+MyReduce.reduce(0, fn(x, acc) -> x + acc end)
+|> IO.inspect
diff --git a/src/code/2/my_red.out b/src/code/2/my_red.out
new file mode 100644
index 0000000..13af7eb
--- /dev/null
+++ b/src/code/2/my_red.out
@@ -0,0 +1,2 @@
+% elixir my_red.exs
+15
diff --git a/src/code/2/qs.exs b/src/code/2/qs.exs
new file mode 100644
index 0000000..38c90c9
--- /dev/null
+++ b/src/code/2/qs.exs
@@ -0,0 +1,10 @@
+defmodule Quicksort do
+ def sort([]), do: []
+ def sort([h|t]) do
+ lower = t |> Enum.filter(&(&1 <= h))
+ upper = t |> Enum.filter(&(&1 > h))
+ sort(lower) ++ [h] ++ sort(upper)
+ end
+end
+
+1..10 |> Enum.shuffle |> Quicksort.sort |> IO.inspect
diff --git a/src/code/2/qs.out b/src/code/2/qs.out
new file mode 100644
index 0000000..9569cda
--- /dev/null
+++ b/src/code/2/qs.out
@@ -0,0 +1,4 @@
+% elixir qs.exs
+0.28user 0.02system 0:00.27elapsed 112%CPU (0avgtext+0avgdata 38936maxresident)k
+0inputs+8outputs (0major+6654minor)pagefaults 0swaps
+[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
diff --git a/src/code/2/wc.exs b/src/code/2/wc.exs
new file mode 100644
index 0000000..2c7c284
--- /dev/null
+++ b/src/code/2/wc.exs
@@ -0,0 +1,28 @@
+defmodule WordCount do
+
+ defp stream_file(filename) do
+ File.stream!(filename)
+ end
+
+ defp tokenize_words(line) do
+ line |> Stream.flat_map(&String.split/1)
+ end
+
+ defp reduce_words(words) when is_list(words) do
+ Enum.reduce(words, %{}, &update_count/2)
+ end
+
+ defp update_count(word, acc) do
+ Map.update(acc, word, 1, &(&1 + 1))
+ end
+
+ def count_words(filename) do
+ stream_file(filename)
+ |> tokenize_words
+ |> Enum.to_list
+ |> reduce_words
+ end
+
+end
+
+WordCount.count_words("pg51353.txt") |> IO.inspect(limit: 20)
diff --git a/src/code/2/wc.out b/src/code/2/wc.out
new file mode 100644
index 0000000..fa338fb
--- /dev/null
+++ b/src/code/2/wc.out
@@ -0,0 +1,6 @@
+% elixir wc.exs
+%{"Kometevskyite?\"" => 1, "silent" => 1, "cease" => 1, "along," => 1,
+ "Refund\"" => 1, "prepare)" => 1, "black" => 4, "shrunken" => 1, "Man" => 1,
+ "payments" => 3, "Redistribution" => 1, "Gutenberg:" => 1, "SEND" => 1,
+ "first" => 3, "accepted" => 1, "whole" => 9, "happened.\"" => 1,
+ "casually," => 1, "forward." => 2, "thoroughly" => 1, ...}
diff --git a/src/func-w-elixir.tex b/src/func-w-elixir.tex
index ea5bdd5..ee6e739 100644
--- a/src/func-w-elixir.tex
+++ b/src/func-w-elixir.tex
@@ -1,6 +1,8 @@
-\documentclass{beamer}
+\documentclass[english]{beamer}
\usetheme{Berlin}
\usecolortheme[light,accent=blue]{solarized}
+\usepackage{amsmath}
+\usepackage{unicode-math}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
@@ -9,6 +11,7 @@
\usepackage{lmodern}
\usepackage{listings}
\usepackage{color}
+\usepackage{babel}
\usepackage{tikz}
\usetikzlibrary{trees, shapes.misc, arrows}
\usepackage{pgfkeys}
@@ -24,8 +27,8 @@
frame=signle,
keepspaces=true,
columns=flexible,
- language=Java,
- numbers=left,
+ language=Ruby,
+ numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{solarizedBase00},
showspaces=false,
@@ -35,7 +38,8 @@
stringstyle=\color{solarizedMagenta},
keywordstyle=\color{solarizedCyan},
commentstyle=\color{solarizedGreen},
- tabsize=2
+ tabsize=2,
+ extendedchars=true
}
\title{Learning Functional Programming with Elixir}
@@ -88,7 +92,6 @@
\item{Developer (read gardener)}
\item{Mathematician}
\item{Student}
-\item{Author~(?)}
\end{itemize}
\end{frame}
@@ -101,7 +104,333 @@
\caption{``Functional programming combines the flexibility and power of
abstract mathematics with the intuitive clarity of abstract mathematics.''}
\end{figure}
-XKCD on Functional\cite{website:xkcd_functional}
+XKCD on Functional Programming\cite{website:xkcd_functional}
+\end{frame}
+
+\begin{frame}
+\frametitle{What is Functional Programming?}
+\begin{itemize}
+\item<1->{Functional programming is a paradigm} %you might say pattern
+\item<2->{Prefers ``mathematical'' functions}
+\item<3->{Uses (mostly) immutable data} %depending on "purity"
+\item<4->{Everything is an expression}
+\end{itemize}
+\end{frame}
+
+\begin{frame}
+\frametitle{What is Elixir? Erlang/OTP?}
+\begin{itemize}
+\item{Elixir is a new functional, dynamically typed language}
+\item{Elixir's design is heavily influenced by Erlang's design}
+\item{Erlang is an old functional, dynamically typed language, first appeared
+in 1986}
+\item{Built around concurrency, fault-tolerance, and high-availability}
+\item{Elixir compiles to BEAM (Erlang) bytecode}
+\item{Elixir ``looks'' like Ruby} %but don't even try to write ruby...
+\end{itemize}
+\end{frame}
+
+\section{Elixir Basics}
+
+\begin{frame}[fragile]
+\frametitle{Interactive Elixir}
+\framesubtitle{\texttt{iex}}
+\lstinputlisting{code/1/iex}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Numerals}
+\lstinputlisting[lastline=16]{code/1/numbers}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic types}
+\framesubtitle{Numeral Operators}
+\lstinputlisting[firstline=18]{code/1/numbers}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Atoms}
+\lstinputlisting[lastline=10]{code/1/atoms}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Atom Functions}
+\lstinputlisting[firstline=12]{code/1/atoms}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Booleans}
+\lstinputlisting[lastline=6]{code/1/booleans}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Boolean Operators}
+\lstinputlisting[firstline=8]{code/1/booleans}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Lists}
+\lstinputlisting[lastline=12]{code/1/lists}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{List Operations}
+\lstinputlisting[firstline=14]{code/1/lists}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Tuples}
+\lstinputlisting[lastline=6]{code/1/tuples}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Tuple Operations}
+\lstinputlisting[firstline=8]{code/1/tuples}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Binaries}
+\lstinputlisting[lastline=8]{code/1/binaries}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Binary Operations}
+\lstinputlisting[firstline=10]{code/1/binaries}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Maps}
+\lstinputlisting[lastline=10]{code/1/maps}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Map Operations}
+\lstinputlisting[firstline=12]{code/1/maps}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Basic Types}
+\framesubtitle{Functions}
+\lstinputlisting{code/1/functions}
+\end{frame}
+
+\begin{frame}
+\frametitle{Dispelling Assignment}
+\framesubtitle{There is no spoon}
+\begin{itemize}
+\item{\texttt{=} does \textbf{not} mean \textit{assign}}
+\item{\texttt{x = 1} is not \textit{assign 1 to \texttt{x}}}
+\item{\texttt{=} is a \textit{match} operator}
+\begin{itemize}
+\item{\texttt{=} is a constraint-solving operator}
+\end{itemize}
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Pattern Matching}
+\lstinputlisting[lastline=8]{code/1/patterns}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Pattern Matching}
+\lstinputlisting[firstline=10,lastline=28]{code/1/patterns}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Pattern Matching}
+\lstinputlisting[firstline=30,lastline=41]{code/1/patterns}
+\end{frame}
+
+\begin{frame}
+\frametitle{Pattern Matching}
+\framesubtitle{Brief Introduction to IEEE-754}
+\begin{itemize}
+\item{64-bit floating point (doubles) numbers are represented using IEEE-754}
+\item{32-bit (single/\texttt{float}) and 128-bit (quadurpals) are similarly
+represented with varying number of bits for each component}
+\item{There are four main components}
+\begin{itemize}
+\item{sign, ±, 1 bit}
+\item{exponent, 11 bits}
+\item{fraction (mantissa), 52 bits}
+\item{bias, built-in, typcially $1023$ for doubles}
+\end{itemize}
+\end{itemize}
+\end{frame}
+
+\begin{frame}
+\frametitle{Pattern Matching}
+\framesubtitle{Brief Introduction to IEEE-754}
+To convert from binary bits to a ``float'', we can use the following formula:
+$$
+{-1}^{\text{sign}} \cdot{}
+\frac{1 + \text{mantissa}}{2^{52}}
+\cdot{} 2^{\text{exponent} - \text{bias}}
+$$
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Pattern Matching}
+\lstinputlisting[firstline=43]{code/1/patterns}
+\end{frame}
+
+\section{Functional Approach}
+
+\begin{frame}
+\frametitle{The Functional Approach}
+\framesubtitle{To all the things!}
+\begin{itemize}
+\item{Less iteration} %sorta
+\item{More (Tail) Recursion} %yay!
+\item{Performance}
+\end{itemize}
+\end{frame}
+
+\begin{frame}
+\frametitle{Fibonacci}
+Because no functional introduction is complete without it.
+\begin{align*}
+F_n &= F_{n-1} + F_{n-2} \\
+F_0 &= 0 \\
+F_1 &= 1
+\end{align*}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Fibonacci}
+\lstinputlisting[numbers=left]{code/2/fib_rec.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Fibonacci}
+\framesubtitle{Iteratively}
+\lstinputlisting[numbers=left]{code/2/fib_itr.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Fibonacci Performance}
+\lstinputlisting[language=bash]{code/2/fib_perf.out}
+\end{frame}
+
+\begin{frame}
+\frametitle{Quicksort}
+\begin{itemize}
+\item{Similar to merge sort}
+\item{Sort by partitioning}
+\item{Has a nice recursive definition} %more yay!
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Quicksort}
+\lstinputlisting[numbers=left]{code/2/qs.exs}
+\lstinputlisting{code/2/qs.out}
+\end{frame}
+
+\begin{frame}
+\frametitle{Map-Reduce}
+\begin{itemize}
+\item<1->{Functional way to process collections}
+\item<2->{Can be (partially) pipelined}
+\item<3->{Mapping can be lazy}
+\item<4->{Map is Reduce} %with a widening accumlator
+\item<5->{They are ``folds''}
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Map-Reduce}
+\framesubtitle{Implementing our own Map}
+\lstinputlisting[numbers=left]{code/2/my_map.exs}
+\lstinputlisting{code/2/my_map.out}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Map-Reduce}
+\framesubtitle{Implementing our own (simple) Reduce}
+\lstinputlisting[numbers=left]{code/2/my_red.exs}
+\lstinputlisting{code/2/my_red.out}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Map-Reduce}
+\framesubtitle{Map-Redux}
+\lstinputlisting[numbers=left]{code/2/my_map_red.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Map-Reduce}
+\framesubtitle{Map-Redux}
+\lstinputlisting{code/2/my_map_red.out}
+\end{frame}
+
+\begin{frame}
+\frametitle{Word Counting}
+\begin{itemize}
+\item{Stream lines out of a file}
+\item{Tokenize into words}
+\item{Reduce words and print results}
+\end{itemize}
+\end{frame}
+
+\begin{frame}
+\frametitle{Word Counting}
+\begin{figure}
+\begin{tikzpicture}
+ \node (stream) at (0, 0) {Stream};
+ \node (tokenize) at (2, 0) {Tokenize};
+ \node (reduce) at (4, 0) {Reduce};
+ \node (print) at (4, -2) {Print};
+ \draw[-o] (stream) -- (tokenize);
+ \draw[-o] (tokenize) -- (reduce);
+ \draw[-o] (reduce) -- (print);
+\end{tikzpicture}
+\end{figure}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Word Counting}
+\framesubtitle{Streaming Data}
+\lstinputlisting[numbers=left,firstline=3,lastline=5]{code/2/wc.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Word Counting}
+\framesubtitle{Tokenizing Words}
+\lstinputlisting[numbers=left,firstline=7,lastline=9]{code/2/wc.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Word Counting}
+\framesubtitle{Reducing Words}
+\lstinputlisting[numbers=left,firstline=11,lastline=17]{code/2/wc.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Word Counting}
+\framesubtitle{Counting Words}
+\lstinputlisting[numbers=left,firstline=19,lastline=24]{code/2/wc.exs}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Word Counting}
+\framesubtitle{Results}
+\lstinputlisting{code/2/wc.out}
\end{frame}
\section*{References}
diff --git a/src/references.bib b/src/references.bib
index 37eb634..3780c6b 100644
--- a/src/references.bib
+++ b/src/references.bib
@@ -5,3 +5,17 @@
@misc{website:elixir-lang,
howpublished="\url{http://elixir-lang.org/}"
}
+@book{book:programming_elixir,
+ author="Dave Thomas",
+ howpublished="\url{https://pragprog.com/book/elixir/programming-elixir}",
+ title="Programming Elixir",
+ publisher="Pragmatic Bookshelf",
+ year="2014"
+}
+@book{book:programming_phoenix,
+ author="Chris McChord and Bruce Tate and José Valim",
+ title="Programming Elixir",
+ publisher="Pragmatic Bookshelf",
+ year="2016",
+ howpublished="\url{https://pragprog.com/book/phoenix/programming-phoenix}"
+}