x y) y x)) (defun *minimum* (lst) (do ((numbers lst (cdr -6ren">
gpt4 book ai didi

lisp - 定义 "minimum"函数以返回列表中的最小值,使用另一个返回两个数字中较小者的函数

转载 作者:行者123 更新时间:2023-12-04 22:34:17 27 4
gpt4 key购买 nike

(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 说“最小”函数中的变量“numbers”是未绑定(bind)的,尽管我认为我已经将它绑定(bind)到“lst”。我错过了什么?

最佳答案

Do 并行绑定(bind)。 result的初值表达式为(cdr numbers)numbers未绑定(bind)。 Do*会在这里工作。

关于lisp - 定义 "minimum"函数以返回列表中的最小值,使用另一个返回两个数字中较小者的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59920951/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com