From c9f43faf3eef9510b5afbf19618e34ca75f03f78 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Sat, 8 Jan 2011 16:03:17 +0530
Subject: [PATCH] solutions to 3.7 and 3.8. Very thought provoking indeed...

---
 src/sicp/ex3_7.rkt | 27 +++++++++++++++++++++++++++
 src/sicp/ex3_8.rkt | 12 ++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 src/sicp/ex3_7.rkt
 create mode 100644 src/sicp/ex3_8.rkt

diff --git a/src/sicp/ex3_7.rkt b/src/sicp/ex3_7.rkt
new file mode 100644
index 0000000..51d01e2
--- /dev/null
+++ b/src/sicp/ex3_7.rkt
@@ -0,0 +1,27 @@
+#lang racket
+
+(define (make-account balance password)
+  (define (withdraw amount)
+    (if (>= balance amount)
+        (begin (set! balance (- balance amount))
+               balance)
+        "Insufficient funds"))
+  (define (deposit amount)
+    (set! balance (+ balance amount))
+    balance)
+  (define (dispatch given-password m)
+    (if (eq? given-password password)
+        (cond ((eq? m 'withdraw) (lambda (amt) (withdraw amt)))
+              ((eq? m 'deposit) (lambda (amt) (deposit amt)))
+              (else (error "Unknown request -- MAKE-ACCOUNT"
+                           m)))
+        (lambda (temp) "Incorrect password")))
+  dispatch)
+
+(define (make-joint account acc-password joint-password)
+  (define (dispatch given-password m)
+    (if (eq? given-password joint-password)
+        (account acc-password m)
+        (lambda (temp) "incorrect password!")))
+  dispatch)
+  
\ No newline at end of file
diff --git a/src/sicp/ex3_8.rkt b/src/sicp/ex3_8.rkt
new file mode 100644
index 0000000..6274bad
--- /dev/null
+++ b/src/sicp/ex3_8.rkt
@@ -0,0 +1,12 @@
+#lang racket
+
+(define f
+  (let ((x 0))
+    (lambda (y)
+      (set! x (+ x 1))
+      (cond 
+        ((and (= x 1) (= y 0)) -1)
+        ((and (= x 2) (= y 1)) 1)
+        ((and (= x 1) (= y 1)) 0)
+        ((and (= x 2) (= y 0)) 1)))))
+      
\ No newline at end of file
-- 
2.45.2