Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a "minimum" function to return the minimum of a list using another function that returns the smaller of two numbers

(defun *smaller* (x y)
  ( if (> x y) y
        x))
(defun *minimum* (lst)
  (do ((numbers lst (cdr numbers))
       (result (car numbers) (*smaller* result (car numbers))))
      ((null numbers) result)))

LISP says that variable "numbers" in "minimum" function is an unbound one although I think I've bound it to "lst". What am I missing?

like image 828
Phan Anh Đặng Avatar asked Dec 19 '25 21:12

Phan Anh Đặng


1 Answers

Do binds in parallel. The expression for the initial value of result is (cdr numbers), and numbers is unbound there. Do* would work here.

like image 113
Joshua Taylor Avatar answered Dec 24 '25 11:12

Joshua Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!