second commit

This commit is contained in:
didier amyot committed 2017-03-12 19:38:27 -04:00
1 parent bc26778e41
commit 6d7a5afe21
92 files changed
+8207 -16

No files matched your search

+71 -7
View File
@@ -1,15 +1,79 @@
(ns transducerpres.slides.what
(:require [transducerpres.slides.util :refer [defslide]]))
(:require [transducerpres.slides.util :refer [defslide defmarkdownslide clj-code markdown-slide markdown-part]]))
(defslide title
[:h3 "What is a Transducer?"])
(defslide wikipedia-definition
[:h4 "According to Wikipedia"]
[:cite "A transducer is a device that converts one form of energy to another"]
[:cite "..."]
[:cite "Transducers are often employed at the boundaries of automation"])
(defmarkdownslide wikipedia-definition
"#### According to Wikipedia"
"> A **transducer** is a device that converts one form of energy to another"
"> ..."
">Transducers are often employed at the boundaries...")
(defmarkdownslide clojuredoc-definition
"#### According to clojuredoc"
"A **transducer** (sometimes referred to as **xform** or **xf**) is a "
"transformation from one reducing function to another")
(defmarkdownslide does-not-help-much
"#### That does not help much"
"Instead let take a look at what transducer try to solve")
(defslide classical-problem
(markdown-part
"#### Classical problem: $ \\sum_{n=0}^{N-1} 2 \\cdot n + 3 $")
(clj-code
"(defn classic-sum [N]"
" (let [all-numbers (range)"
" input (take N all-numbers)"
" times-two (map #(* 2 %) input)"
" times-two-plus-three (map #(+ 3 %) times-two)]"
" (reduce + 0 times-two-plus-three)))")
(markdown-part
"node: Here we produce two lists when we actually do not need any"))
(defslide classical-problem-with-channel
(markdown-part
"#### And the solution to a very similar problem requires a re-written")
(clj-code
"(require '[clojure.core.async :as async])")
(clj-code
"(defn classic-sum-channel [N]"
" (let [all-numbers (async/to-chan (range))"
" input (async/take N all-numbers)"
" times-two (async/map< #(* 2 %) input)"
" times-two-plus-three (async/map< #(+ 3 %) times-two)]"
" (async/reduce + 0 times-two-plus-three)))"
))
(defslide classical-problem-with-transducer
(markdown-part
"#### Transducers simplify all the above fiddling")
(clj-code
"(require '[clojure.core.async :as async])")
(clj-code
"(defn xform [N] ;; transducers are usually named xform or xf"
" (comp (take N)"
" (map #(* 2 %))"
" (map #(+ 3 %))))"
""
"(defn trans-classic-sum [N]"
" (transduce (xform N) + 0 (range)))"
""
"(defn trans-classic-sum-channel [N]"
" (async/transduce (xform N) + 0 (async/to-chan (range))))"
))
(defmarkdownslide transducer-formal-definition
"Hence a **transducer** is a data pipeline \"functional interface\""
"that is un aware of the underlying data structure.")
(defslide what-is-a-tranducer
title
wikipedia-definition)
wikipedia-definition
clojuredoc-definition
does-not-help-much
classical-problem
classical-problem-with-channel
classical-problem-with-transducer
transducer-formal-definition)