sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit a2fc1fda91fbae99f3f14b3370ccd67871ac6c87
parent 2f4626b7ff7c0b41658a8d41f81e56eac8befc7b
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 15 Jul 2019 19:19:48 -0400

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.

Diffstat:
net/ricketyspace/sicp/two/twentynine.scm | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 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))))