]> git.rkrishnan.org Git - sicp.git/commitdiff
solution to 2.24. Please look at the correctness of the box and arrow diagram
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Fri, 2 Jul 2010 07:18:02 +0000 (12:48 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Fri, 2 Jul 2010 07:18:02 +0000 (12:48 +0530)
src/sicp/ex2_24.clj [new file with mode: 0644]

diff --git a/src/sicp/ex2_24.clj b/src/sicp/ex2_24.clj
new file mode 100644 (file)
index 0000000..b027573
--- /dev/null
@@ -0,0 +1,34 @@
+; -*-text-*-
+(comment
+(list 1 (list 2 (list 3 4)))
+;;=>  (1 (2 (3 4)))
+)
+
+;; box and arrow notation
+
+         --- ---      --- --- 
+        |   |   |--> |   | \ |
+         --- ---      --- --- 
+          |            |      
+          |            |      
+          -> 1         |
+                      --- ---      --- --- 
+                     |   |   |--> |   | \ |
+                      --- ---      --- --- 
+                       |            |      
+                       |            |      
+                       -> 2         |
+                                   --- ---      --- --- 
+                                  |   |   |--> |   | \ |
+                                   --- ---      --- --- 
+                                    |            |      
+                                    |            |      
+                                    -> 3         -> 4
+
+The key to draw box-and-arroy diagram is to look at the list and draw
+the outermost level elements in the top and then work innerwards (downwards)
+from there. So, (1 (2 (3 4))) has two elements at the top :
+1 and (list 2 (list 3 4))
+
+(2 (3 4)) has two elements in it: 2 and (list 3 4) and then we have (3 4).
+This translated to the above diagram.