1

Why am i getting this error:

The value (2 (2 (2 (2 (2) 2) 2) 2) 2) is not of type NUMBER when binding SB-KERNEL::X [Condition of type TYPE-ERROR]

when calling the subst-if with the follwoing test function:

(defun 2p (N) (= N 2))
(subst-if 3 #'2p '(2 (2 (2 (2 (2) 2) 2) 2) 2))

1 Answers1

2

You have to use equal or eql (or any function that can compare arbitrary values, for your case eql being faster) in the 2p function, as the function has to be able to receive any value inside the argument you're passing (the list with sublists). The = function is meant for numbers.

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

The definition for =:

* (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
Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87