如果在Common Lisp中,如果在树上抛出错误,则工作

问题描述 投票:0回答:1

我为什么会收到此错误:

值(2(2(2(2(2(2)2)2)2)2)2)不是类型数绑定SB-KERNEL :: X时[TYPE-ERROR类型的条件]

当使用以下测试功能调用subst-if时:

(defun 2p (N) (= N 2))
(subst-if 3 #'2p '(2 (2 (2 (2 (2) 2) 2) 2) 2))
common-lisp sbcl subst
1个回答
0
投票

equal函数中必须使用eqleql(或任何可以比较任意值的函数,对于您的情况2p更快),因为该函数必须能够接收任何值在您要传递的参数内(带有子列表的列表)。 =功能用于数字。

(defun 2p (N) (eql N 2))

=的定义:

* (describe #'=)
#<FUNCTION =>
  [compiled function]


Lambda-list: (NUMBER &REST SB-KERNEL::MORE-NUMBERS)
Declared type: (FUNCTION (NUMBER &REST NUMBER)
                (VALUES BOOLEAN &OPTIONAL))
Derived type: (FUNCTION (NUMBER &REST T) (VALUES BOOLEAN &OPTIONAL))
Documentation:
  Return T if all of its arguments are numerically equal, NIL otherwise.
Known attributes: foldable, flushable, unsafely-flushable, movable, predicate, commutative
Source file: SYS:SRC;CODE;NUMBERS.LISP
© www.soinside.com 2019 - 2024. All rights reserved.