定义“最小"函数使用另一个函数返回列表的最小值,该函数返回两个数字中的较小者 [英] Defining a "minimum" function to return the minimum of a list using another function that returns the smaller of two numbers

查看:78
本文介绍了定义“最小"函数使用另一个函数返回列表的最小值,该函数返回两个数字中的较小者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(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说最小"函数中的变量数字"是一个未绑定的变量,尽管我认为我已将其绑定到第一".我想念什么?

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?

推荐答案

Do 并行绑定. result 的初始值的表达式是(cdr数字),而 numbers 在那里不受约束. Do * 可以在这里工作.

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

这篇关于定义“最小"函数使用另一个函数返回列表的最小值,该函数返回两个数字中的较小者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆