(define (mobile-balanced? mobile) (let ((l-branch (left-branch mobile)) (r-branch (right-branch mobile))) (and (= (* (branch-length l-branch) (branch-weight l-branch)) (* (branch-length r-branch) (branch-weight r-branch))) (branch-balanced? l-branch) (branch-balanced? r-branch)))) (define (branch-balanced? branch) (let ((structure (branch-structure branch))) (if (pair? structure) (mobile-balanced? structure) true)))
Thanks to abstraction we only need to change some selectors.