From ee1a91b8cab28dfa115992fc9e02751519c2c155 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com> Date: Tue, 23 Mar 2010 00:46:58 +0530 Subject: [PATCH] first commit --- README | 1 + ch1/square.clj | 9 +++++++++ misc/argue.clj | 12 ++++++++++++ misc/plural.clj | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 README create mode 100644 ch1/square.clj create mode 100644 misc/argue.clj create mode 100644 misc/plural.clj diff --git a/README b/README new file mode 100644 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 index 0000000..5671487 --- /dev/null +++ b/ch1/square.clj @@ -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 index 0000000..f423b2f --- /dev/null +++ b/misc/argue.clj @@ -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 index 0000000..6ded4e0 --- /dev/null +++ b/misc/plural.clj @@ -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 -- 2.45.2