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 pointer to a good online resource (and perhaps a specific page within one) would be great!
+1
A:
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.
Svante
2010-03-30 00:07:58
justkt
2010-03-30 00:10:35
+1
A:
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.
Zak
2010-03-30 11:35:00
For the purposes of my homework, I'm pretty sure that I can assume all functions passed are predicates, so using `apply` or `funcall` on something that passes `functionp` should work. But it's good to know for general use that there's no `predicatep` type of call.
justkt
2010-03-30 14:07:05