本文介绍了LISP:以谓词为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 (DEFFL per(FL)
(cond) ((FL)'working)
(T'anything)))

(per'numberp 3)


$ b $ p

结果会产生错误:


解决方案

正如,
Common Lisp是一个Lisp-2,也就是你
需要:

 (defun per(FL)
(if(funcall FL)
'working
'其他))
(每##numberp 3)
==>工作
(每##numberp3)
==>其他

另见。


I want a predicate as a parameter of a function.

(DEFUN per (F L)
    (cond ((F L) 'working)
          (T     'anything)))

(per 'numberp 3)

as result it raises an error:

解决方案

As explained in Technical Issues of Separation in Function Cells and Value Cells,Common Lisp is a Lisp-2, i.e., youneed funcall:

(defun per (F L)
  (if (funcall F L)
      'working
      'other))
(per #'numberp 3)
==> WORKING
(per #'numberp "3")
==> OTHER

See also apply.

这篇关于LISP:以谓词为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:55