LISP:以谓词为参数 [英] LISP: with predicate as parameter
本文介绍了LISP:以谓词为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(DEFFL per(FL)
(cond) ((FL)'working)
(T'anything)))
(per'numberp 3)
$ b $ p
结果会产生错误:
形式为(FL)的未定义运算符F.
解决方案
正如函数单元和值单元分离的技术问题,
Common Lisp是一个Lisp-2,也就是你
需要 funcall
:
(defun per(FL)
(if(funcall FL)
'working
'其他))
(每##numberp 3)
==>工作
(每##numberp3)
==>其他
另见 apply
。
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:
Undefined operator F in form (F L).
解决方案
As explained in Technical Issues of Separation in Function Cells and Value Cells,
Common Lisp is a Lisp-2, i.e., you
need funcall
:
(defun per (F L)
(if (funcall F L)
'working
'other))
(per #'numberp 3)
==> WORKING
(per #'numberp "3")
==> OTHER
See also apply
.
这篇关于LISP:以谓词为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文