by shigemk2

当面は技術的なことしか書かない

対話によるCommon Lisp入門 38 member その3

= は数が等しいかどうかを調べるものなので、
シンボルと比較するとエラーになる

[1]> (defun member$ (item list)
(if (null lst) nil
(if (= item (first lst)) lst
(member$ item (rest lst)))))
MEMBER$
[2]> (member$ 'tea '(juice tea coffee))

*** - IF: variable LST has no value
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead of LST.
STORE-VALUE    :R2      Input a new value for LST.
ABORT          :R3      Abort main loop
Break 1 [3]> (= 5 5)
T
Break 1 [3]> (= 'tea 'tea)

*** - =: TEA is not a number
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort debug loop
ABORT          :R3      Abort main loop

故に、こう。

[10]> (defun member$ (item lst)
(if (null lst) nil
(if (eql item (first lst)) lst
(member$ item (rest lst)))))
MEMBER$
[11]> (member$ 'tea '(juice tea coffee))
(TEA COFFEE)