SCIP 1.4
Exercise 1.4. Observe that our model of evaluation allows for combinations whose operators are
compound expressions. Use this observation to describe the behavior of the following procedure:
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
I just convert the scheme vertion to lisp version!
CL-USER> (defun a-plus-abs-b (a b)
(funcall (if (> b 0) #'+
#'-)
a
b))
A-PLUS-ABS-B
CL-USER> (a-plus-abs-b 2 -3)
5
CL-USER> (a-plus-abs-b 2 3)
5
CL-USER> (a-plus-abs-b -2 3)
1
Edit in Emacs with Slime and Steel Bank Common Lisp.