common lisp 求助。。。

Define an iterative function RANGE that takes a list of numbers (at least one long) and returns a list of length two of the smallest and largest numbers. Function RANGE should have the following behavior:

(-1 8)

0
(defun range (lst) (list (apply #'min lst) (apply #'max lst)))

0

COMMON LISP 人工智能
0
```(defun min-and-max (lst)
(list (reduce #'(lambda (a b) (if (< a b) a b)) lst)
(reduce #'(lambda (a b) (if (> a b) a b)) lst)))```

0
```(defun range (lst)
(let ((l (copy-list lst)))
(setf l (sort l #'<))
`(,(car l) ,@(last l))))```
0

))))))))))))))))))))))))))))))))))

)))))))))))))))))))))))))))

)))))))))))))))

0

引用来自“crab2313”的答案

(defun range (lst) (list (apply #'min lst) (apply #'max lst)))

0

引用来自“帝归”的答案

```(defun min-and-max (lst)
(list (reduce #'(lambda (a b) (if (< a b) a b)) lst)
(reduce #'(lambda (a b) (if (> a b) a b)) lst)))```

0

```(defun RANGE (1st)
(labels ((iter (&rest args)
(destructuring-bind ((small large) &optional ((h &rest a))) args
(if (null h)
(car args)
(iter (list (min small h)
(max large h))
a)))))
(iter (list (car 1st) (car 1st))
(cdr 1st))))```

0

引用来自“redraiment”的答案

```(defun RANGE (1st)
(labels ((iter (&rest args)
(destructuring-bind ((small large) &optional ((h &rest a))) args
(if (null h)
(car args)
(iter (list (min small h)
(max large h))
a)))))
(iter (list (car 1st) (car 1st))
(cdr 1st))))```

THx