【问题标题】:Common LISP passing fewer arguments than required - what is going on?Common LISP 传递的参数少于所需的参数 - 这是怎么回事?
【发布时间】:2016-02-24 22:34:03
【问题描述】:

我目前正在研究一些涉及多项式的代码(不是我的),以便更好地理解函数式 LISP 编程。

(define collect-terms(a)
  (sort a #'compare))

(defun compare(a b)
  (llt (car (cdr a)) (car (cdr b))))

我不明白 compare 方法在函数定义声明两个时在 collect-terms 中调用时如何只接受一个参数。

在这种情况下,比较成功地取出它传递的列表的子列表,并将它们用作 a 和 b 的值。

【问题讨论】:

  • Common Lisp 没有define

标签: functional-programming lisp common-lisp


【解决方案1】:

collect-terms 根本没有调用compare。它将compare 传递给sort 函数,该函数将使用两个参数调用compare

【讨论】:

  • 但是 compare 仍然需要两个参数,不是吗?即使只有一个列表可以使用,它是如何使用这些的?还是我理解错了?
  • sort 调用你给它的任何比较函数,它来自你给它的列表中的元素,一次两个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 2011-07-26
  • 2016-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多