]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_24.clj
Solution to 4.44. A bit too verbose. Can be improved by better
[sicp.git] / src / sicp / ex2_24.clj
1 ; -*-text-*-
2 (comment
3 (list 1 (list 2 (list 3 4)))
4 ;;=>  (1 (2 (3 4)))
5 )
6
7 ;; box and arrow notation
8
9          --- ---      --- --- 
10         |   |   |--> |   | \ |
11          --- ---      --- --- 
12           |            |      
13           |            |      
14           -> 1         |
15                       --- ---      --- --- 
16                      |   |   |--> |   | \ |
17                       --- ---      --- --- 
18                        |            |      
19                        |            |      
20                        -> 2         |
21                                    --- ---      --- --- 
22                                   |   |   |--> |   | \ |
23                                    --- ---      --- --- 
24                                     |            |      
25                                     |            |      
26                                     -> 3         -> 4
27
28 The key to draw box-and-arroy diagram is to look at the list and draw
29 the outermost level elements in the top and then work innerwards (downwards)
30 from there. So, (1 (2 (3 4))) has two elements at the top :
31 1 and (list 2 (list 3 4))
32
33 (2 (3 4)) has two elements in it: 2 and (list 3 4) and then we have (3 4).
34 This translated to the above diagram.