From: Ramakrishnan Muthukrishnan Date: Mon, 22 Mar 2010 19:16:58 +0000 (+0530) Subject: first commit X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv/prod.html?a=commitdiff_plain;h=ee1a91b8cab28dfa115992fc9e02751519c2c155;p=sicp.git first commit --- ee1a91b8cab28dfa115992fc9e02751519c2c155 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