forked from clj-syd/curriculum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule5.html
111 lines (97 loc) · 3.17 KB
/
module5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 (experimental) for Mac OS X https://github.com/w3c/tidy-html5/tree/c63cc39">
<title>ClojureBridge slides</title>
<link rel="stylesheet" href="assets/reveal.js/css/reveal.css">
<link rel="stylesheet" href="assets/mozilla-theme.css" id=
"theme">
<link rel="stylesheet" href=
"assets/reveal.js/plugin/highlight/github.min.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="slide-title intro">Module 5</h1>
</section>
<section>
<h2 class="slide-title chapter">Common, core
functions</h2>
</section>
<section>
<h3 class="slide-title slide">Comparison functions</h3>
<pre>
<code class="clojure">(= 1 2) ;=> false
(> 4 3) ;=> true
(>= 4 5) ;=> false
(< -1 1) ;=> true
(<= -1 -2) ;=> false
(< 1 5 9) ;=> true
(< 1 5 3) ;=> false</code></pre>
</section>
<section>
<h3 class="slide-title slide">Using comparison
functions</h3>
<pre>
<code class="clojure">(defn meaning-of-life?
[x]
(= x 42))</code></pre>
</section>
<section>
<h3 class="slide-title slide">String functions</h3>
<pre>
<code class=
"clojure">(str "Chocolate" ", " "strawberry" ", and " "vanilla")
;;=> "Chocolate, strawberry, and vanilla"</code></pre>
</section>
<section>
<h3>Using <code>str</code> with <code>reduce</code></h3>
<pre>
<code class="clojure">(defn join-with-space
[string1 string2]
(str string1 " " string2))
(reduce join-with-space
["i" "like" "peanut" "butter" "and" "jelly"])
;;=> "i like peanut butter and jelly"</code></pre>
</section>
<section>
<h3>Using <code>str</code> with <code>reduce</code></h3>
<pre>
<code class="clojure">(reduce join-with-space
["i" "like" "peanut" "butter" "and" "jelly"])
;;=> "i like peanut butter and jelly"
(join-with-space "i" "like")
(join-with-space "i like" "peanut")
(join-with-space "i like peanut" "butter")
(join-with-space "i like peanut butter" "and")
(join-with-space "i like peanut butter and" "jelly")</code></pre>
</section>
<section>
<h3 class="slide-title slide">Anonymous functions</h3>
<pre>
<code class="clojure">(map (fn [x] (* 3 x)) [1 2 3]) ;=> [3 6 9]
(reduce (fn [x y] (+ x y)) [1 2 3]) ;=> 6
(reduce
(fn [s1 s2] (str s1 " " s2))
["i" "like" "peanut" "butter" "and" "jelly"])
;=> "i like peanut butter and jelly"</code></pre>
</section>
</div>
</div><script src="assets/reveal.js/lib/js/head.min.js">
</script> <script src="assets/reveal.js/js/reveal.js">
</script> <script>
Reveal.initialize({
history: true,
dependencies: [
{src: "assets/reveal.js/plugin/markdown/marked.js"},
{src: "assets/reveal.js/plugin/markdown/markdown.js"},
{src: "assets/reveal.js/plugin/highlight/highlight.js",
async: true,
callback: function () { hljs.initHighlightingOnLoad()}},
{src: "assets/reveal.js/plugin/notes/notes.js"}
]});
</script>
</body>
</html>