开发者

Lisp: Determine if a list contains a predicate

As part of a homework assignment in Lisp, I am to use apply or funcall on any predicates I find. My question (uncovered in the coursework) is: how do I know when I've found a predicate in my list of arguments? I've done some basic google searching and come up with nothing so far. We're allowed to use Lisp references for the assignment - even a point开发者_开发知识库er to a good online resource (and perhaps a specific page within one) would be great!


The canonical reference is the Common Lisp Hyperspec.

I don't know what your assignment is exactly, but you can either check each argument against a list of possible predicates, or perhaps determine if your argument is a function (functionp), if you can assume that all functions passed in would be predicates.


To add to Svante's answer: I don't think there's any way to verify that a given function is a predicate as you might be able to do in a statically-typed language. Most CL implementations do provide introspection functions like SBCL's sb-introspect:function-arglist that will allow you to check to see that only one argument is accepted. It's no guarantee that the function's behavior is sane, but it may be better than nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜