From 88e008e0e0d464ca44b87107a73f76a0a020ef27 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Sun, 5 Sep 2010 22:38:04 +0530
Subject: [PATCH] Fixed a bug with the rest case input of '(x + 3 * (x + y +
 2))

---
 src/sicp/ex2_58b.clj | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/sicp/ex2_58b.clj b/src/sicp/ex2_58b.clj
index 9d2ffc9..9740003 100644
--- a/src/sicp/ex2_58b.clj
+++ b/src/sicp/ex2_58b.clj
@@ -101,19 +101,35 @@
   (and (list? x) (= (op-expr x) '+)))
 
 (defn addend [s]
-  (first-expr s))
+  (let [a (first-expr s)]
+    (if (and (list? a)
+             (= (count a) 1))
+      (first a)
+      a)))
 
 (defn augend [s]
-  (rest-expr s))
+  (let [a (rest-expr s)]
+    (if (and (list? a)
+             (= (count a) 1))
+      (first a)
+      a)))
 
 (defn product? [x]
   (= (second x) '*))
 
 (defn multiplier [p]
-  (first p))
+  (let [m (first p)]
+    (if (and (list? m)
+             (= (count m) 1))
+      (first m)
+      m)))
 
 (defn multiplicand [p]
-  (rest (rest p)))
+  (let [m (rest (rest p))]
+    (if (and (list? m)
+             (= (count m) 1))
+      (first m)
+      m)))
 
 (defn make-exponentiation [b n]
   (cond (=number? b 1) 1
-- 
2.45.2