; apply-binary-operator ; ; input to the function: ; the name of a binary boolean operator ; a list of Ls and Hs ; two bolean values ; one variable that's either L or H ; a second variable that's either L or H ; output ; the result of applying the operator to the values ; ; examples ; (apply-binary-operator '(L L L H) 'H 'L) -> 'L ; (apply-binary-operator '(L H H H) 'L 'H) -> 'H ; (define (apply-binary-operator operator-name first-input second-input) (if (eq? first-input 'L) (if (eq? second-input 'L) (list-ref operator-name 0) (list-ref operator-name 1)) (if (eq? second-input 'L) (list-ref operator-name 2) (list-ref operator-name 3)))) (define (make-binary-operator operator-name) (lambda (first-input second-input) (apply-binary-operator operator-name first-input second-input))) (define (select-first-or-second input-list value) (if (eq? value 'H) (list-ref input-list 1) (list-ref input-list 0))) (define (eval-nested-binary nested-operator v1 v2) (select-first-or-second (select-first-or-second nested-operator v1) v2))