]> git.rkrishnan.org Git - sicp.git/commitdiff
first commit
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 22 Mar 2010 19:16:58 +0000 (00:46 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 22 Mar 2010 19:16:58 +0000 (00:46 +0530)
README [new file with mode: 0644]
ch1/square.clj [new file with mode: 0644]
misc/argue.clj [new file with mode: 0644]
misc/plural.clj [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..08828d8
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+This is the namespace for SICP examples, exercises and problems.
diff --git a/ch1/square.clj b/ch1/square.clj
new file mode 100644 (file)
index 0000000..5671487
--- /dev/null
@@ -0,0 +1,9 @@
+(ns sicp-clj.ch1)
+
+(defn square [x] (* x x))
+
+(defn sum-of-squares [x y]
+  (+ (square x) (square y)))
+
+(defn f [a]
+  (sum-of-squares (+ a 1) (* a 2)))
\ No newline at end of file
diff --git a/misc/argue.clj b/misc/argue.clj
new file mode 100644 (file)
index 0000000..f423b2f
--- /dev/null
@@ -0,0 +1,12 @@
+(ns sicp-clj)
+
+(defn argue [sentence]
+  (when-not (empty? sentence)
+    (concat (opposite (first sentence)) (argue (rest sentence)))))
+
+(defn opposite [word]
+  (cond (= word "like") "hate"
+       (= word "hate") "like"
+       (= word "wonderful") "terrible"
+       (= word "terrible") "wonderful"
+       :else word))
\ No newline at end of file
diff --git a/misc/plural.clj b/misc/plural.clj
new file mode 100644 (file)
index 0000000..6ded4e0
--- /dev/null
@@ -0,0 +1,5 @@
+;; from Brian Harvey's Spring 2008 lecture 01.
+(defn plural [wd]
+  (if (= (last wd) \y)
+    (apply str (concat (butlast wd) "ies"))
+    (apply str (concat wd "s"))))
\ No newline at end of file