Duplication, Grarh! pasted by elderK on Thu Feb 9 23:16:39 2012

(define (avl-tree-maintain-balance tree stack origin child l-subtree-mod
                                   r-subtree-mod called-on)
  (let loop ((parent origin) (child child))
    (if (null? parent)
        0
        (case (avl-node-balance child)
          ((0 4) 1)
          ((1 3) (if (eq? called-on 'deletion)
                     2)
                 (avl-node-mod-balance
                  parent (if (eq? (avl-node-l-subtree parent) child)
                             l-subtree-mod
                             r-subtree-mod))
                 (loop (avl-stack-pop! stack) parent))
          (else (if (eq? called-on 'insertion)
                    3)
                (avl-node-mod-balance
                 parent (if (eq? (avl-node-l-subtree parent) child)
                            l-subtree-mod
                            r-subtree-mod))
                (loop (avl-stack-pop! stack) parent))))))

Duplication, Grarh! - one possibility? added by arthurmaciel on Fri Feb 10 00:25:29 2012

(define (avl-tree-maintain-balance tree stack origin child l-subtree-mod
                                   r-subtree-mod called-on)
  (let* loop ((parent origin) (child child)
	      (avl-n-m-bal (lambda () (avl-node-mod-balance
				       parent (if (eq? (avl-node-l-subtree parent) child)
						  l-subtree-mod
						  r-subtree-mod))
				   (loop (avl-stack-pop! stack) parent))))
	(if (null? parent)
	    0
	    (case (avl-node-balance child)
	      ((0 4) 1)
	      ((1 3) (if (eq? called-on 'deletion)
			 2)
	       (avl-n-m-bal))
	      (else (if (eq? called-on 'insertion)
			3)
		    (avl-n-m-bal))))))