I have a Lisp function that returns either MAX of two values, or MIN of two values. Right now, my code has relatively complex expressions for evaluating VALUE1 and VALUE2.
(defun treemax (bilist &optional ismin)
(cond
;; Compute minimum
(ismin (min (COMPLEX_EXPRESSION_1) (COMPLEX_EXPRESSION_2)))
;; Compute maximum
(t (max (COMPLEX_EXPRESSION_1) (COMPLEX_EXPRESSION_2)))))
The problem is that COMPLEX_EXPRESSION_1 and COMPLEX_EXPRESSION_2 actually occupy many different lines of code. I would really like not to repeat them. Is there a more efficient way to call it?
Essentially, I'm trying to do this, but not for values, but for unary if functions. If you are familiar with C or its variants, then, in fact, I'm looking for:
((ismin ? min : max) COMPLEX_EXPRESSION_1 COMPLEX_EXPRESSION_2)
At the same time, I conditionally choose which function to send arguments to. It makes sense?
source
share