From 1a13ee14c6c7ad3ccb142e49b95a4a781887be6b Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Sat, 18 Apr 2015 11:26:00 -0700 Subject: [PATCH 1/5] Add asserts for some of the exercises --- src/cljlab/functions.clj | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cljlab/functions.clj b/src/cljlab/functions.clj index 6d92576..df7ae8e 100644 --- a/src/cljlab/functions.clj +++ b/src/cljlab/functions.clj @@ -386,6 +386,9 @@ vector ;; @@ (defn do-nothing [x] ___) + +(assert (= 42 (do-nothing 42))) +(assert (= "wtf"(do-nothing "wtf"))) ;; @@ ;; ** @@ -404,6 +407,10 @@ vector ;; @@ (defn always-thing [__] ___) + +(assert (= :thing (always-thing))) +(assert (= :thing (always-thing 42))) +(assert (= :thing (always-thing "wtf" 42))) ;; @@ ;; ** @@ -515,6 +522,8 @@ vector ;; @@ (defn http-get [url] ___) + +(assert (.contains (http-get "http://www.w3.org") "html")) ;; @@ ;; ** @@ -531,6 +540,9 @@ vector ;; @@ (defn one-less-arg [f x] (fn [& args] ___)) + +(defn add-two-numbers [x y] (+ x y)) +(assert (= 3 ((one-less-arg add-two-numbers 1) 2))) ;; @@ ;; ** @@ -546,8 +558,13 @@ vector ;; @@ (defn two-fns [f g] ___) -;; @@ +(defn add-two [x] (+ 2 x)) +(defn times-ten [x] (* 10 x)) + +(assert (= 12 ((two-fns add-two times-ten) 1))) +(assert (= 30 ((two-fns times-ten add-two) 1))) +;; @@ ;; ** ;;; # Lab Solutions ;;; From f3e2609b85be20006d2ae727f2f2cf96cccf8360 Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Sun, 19 Apr 2015 09:20:05 -0700 Subject: [PATCH 2/5] s/statement/expression/ in one spot --- src/cljlab/flowcontrol.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljlab/flowcontrol.clj b/src/cljlab/flowcontrol.clj index ee6030e..c6fc860 100644 --- a/src/cljlab/flowcontrol.clj +++ b/src/cljlab/flowcontrol.clj @@ -100,7 +100,7 @@ ;; ** ;;; ## `when` ;;; -;;; `when` is a one-armed `if`. It checks a condition and then evaluates any number of statements as a body (so no `do` is required). The value of the last expression is returned. If the condition is false, nil is returned. +;;; `when` is a one-armed `if`. It checks a condition and then evaluates any number of expressions as a body (so no `do` is required). The value of the last expression is returned. If the condition is false, nil is returned. ;;; ;;; `when` communicates to a reader that there is no "else" branch. ;; ** From 2718feaaf3bd82b3788f1fe1ff894c69011053fa Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Sun, 19 Apr 2015 10:42:49 -0700 Subject: [PATCH 3/5] Fix typo --- src/cljlab/flowcontrol.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljlab/flowcontrol.clj b/src/cljlab/flowcontrol.clj index c6fc860..264edcf 100644 --- a/src/cljlab/flowcontrol.clj +++ b/src/cljlab/flowcontrol.clj @@ -514,7 +514,7 @@ ;; ** ;;; ## Euclid's algorithm -;;; [Euclid's algorithm](http://en.wikipedia.org/wiki/Euclidean_algorithm) finds the greatest common divisor of two integers using only substraction. In imperative pseudo-code, it looks like this: +;;; [Euclid's algorithm](http://en.wikipedia.org/wiki/Euclidean_algorithm) finds the greatest common divisor of two integers using only subtraction. In imperative pseudo-code, it looks like this: ;;; ;;; ``` ;;; function gcd(A, B): From 8ae54f3dcdc2911767d7306f53b7797cb94ef8c7 Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Sun, 19 Apr 2015 10:48:28 -0700 Subject: [PATCH 4/5] Fix typo --- src/cljlab/flowcontrol.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljlab/flowcontrol.clj b/src/cljlab/flowcontrol.clj index 264edcf..aa747f1 100644 --- a/src/cljlab/flowcontrol.clj +++ b/src/cljlab/flowcontrol.clj @@ -522,7 +522,7 @@ ;;; if A == 0 ;;; return B ;;; if B == 0 -;;; return B +;;; return A ;;; if A > B ;;; A := A - B ;;; else From 3235e6798e97add4392f52747c5bdd0c1128bda8 Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Sun, 19 Apr 2015 16:01:06 -0700 Subject: [PATCH 5/5] Fix typo --- src/cljlab/polymorphism.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljlab/polymorphism.clj b/src/cljlab/polymorphism.clj index 79ddcba..4da9187 100644 --- a/src/cljlab/polymorphism.clj +++ b/src/cljlab/polymorphism.clj @@ -9,7 +9,7 @@ ;; ** ;;; ## Motivation ;;; -;;; There are many situations where it is useful to provide behavior that varies based on type or value. Clojure provides two different mechanisms to for conditional (polymorphic) behavior: protocols and multimethods. +;;; There are many situations where it is useful to provide behavior that varies based on type or value. Clojure provides two different mechanisms for conditional (polymorphic) behavior: protocols and multimethods. ;;; ;;; Also, Clojure provides two constructs that allow you to create new data "types": records (which we saw in collections earlier) and types. ;;;