summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-07-15 19:19:48 -0400
committerrsiddharth <s@ricketyspace.net>2019-07-15 19:19:48 -0400
commita2fc1fda91fbae99f3f14b3370ccd67871ac6c87 (patch)
treecd3262a510d5ba57274add4d2870a79839a35954
parent2f4626b7ff7c0b41658a8d41f81e56eac8befc7b (diff)
net/ricketyspace: two/twentynine.scm: Add branch-weight.
* net/ricketyspace/sicp/two/twentynine.scm (branch-weight): New function. (total-weight): Remove branch-weight local function.
-rw-r--r--net/ricketyspace/sicp/two/twentynine.scm11
1 files changed, 6 insertions, 5 deletions
diff --git a/net/ricketyspace/sicp/two/twentynine.scm b/net/ricketyspace/sicp/two/twentynine.scm
index cc1380c..8e1aaa2 100644
--- a/net/ricketyspace/sicp/two/twentynine.scm
+++ b/net/ricketyspace/sicp/two/twentynine.scm
@@ -27,12 +27,13 @@
(define (branch-structure branch)
(car (cdr branch)))
+(define (branch-weight b)
+ (let ((bs (branch-structure b)))
+ (cond ((not (pair? bs)) bs)
+ (else (+ (branch-weight (left-branch bs))
+ (branch-weight (right-branch bs)))))))
+
(define (total-weight mobile)
- (define (branch-weight b)
- (let ((bs (branch-structure b)))
- (cond ((not (pair? bs)) bs)
- (else (+ (branch-weight (left-branch bs))
- (branch-weight (right-branch bs)))))))
(+ (branch-weight (left-branch mobile))
(branch-weight (right-branch mobile))))