浏览代码

Add anonymous function examples

Lily Carpenter 10 年之前
父节点
当前提交
6cf4ae3b70
共有 1 个文件被更改,包括 13 次插入3 次删除
  1. 13 3
      presentation.tex

+ 13 - 3
presentation.tex

@@ -149,7 +149,7 @@
149 149
   \frametitle{Hello World}
150 150
   \begin{minted}{clojure}
151 151
     (ns hello-world.core
152
-      (:gen-class))
152
+      (:gen-class)) ; Generate a java class
153 153
 
154 154
     (defn -main
155 155
       "I don't do a whole lot ... yet."
@@ -162,7 +162,7 @@
162 162
   \frametitle{Thread First Macro}
163 163
   \begin{minted}{clojure}
164 164
     (-> "a b c d"
165
-        .toUpperCase
165
+        .toUpperCase ; Calling directly to java
166 166
         (.replace "A" "X")
167 167
         (.split " ")
168 168
         first)
@@ -174,7 +174,7 @@
174 174
   \frametitle{Thread Last Macro}
175 175
   \begin{minted}{clojure}
176 176
     (->> (range)
177
-         (map #(* % %))
177
+         (map #(* % %)) ; Anonymous function
178 178
          (filter even?)
179 179
          (take 10)
180 180
          (reduce +))
@@ -182,5 +182,15 @@
182 182
   \url{http://clojuredocs.org/clojure.core/->>}
183 183
 \end{frame}
184 184
 
185
+\begin{frame}[fragile]
186
+  \frametitle{Anonymous Functions}
187
+  \begin{minted}{clojure}
188
+    (fn [x y]
189
+      (+ x y))
190
+
191
+    #(+ %1 %2)
192
+    #(+ % %) ; Only takes 1 argument
193
+  \end{minted}
194
+\end{frame}
185 195
 \section{Resources}
186 196
 \end{document}