Lisp: Determine if a List Contains a Predicate

As part of the homework in Lisp, I have to use apply or funcall for any predicates that I find. My question (uncovered in the term paper): how do I know when I found my predicate in my argument list? I did some basic searches and came up with nothing. We are allowed to use Lisp links for assignment - even a pointer to a good online resource (and perhaps a specific page within one) will be great!

+3
source share
2 answers

Canonical link Common Lisp Hyperspec .

I don’t know what exactly you assigned, but you can either check each argument for a list of possible predicates, or determine if your argument is a function ( functionp), if you can assume that all the functions passed in will be predicates.

+1
source

To add Svante's answer: I don't think there is a way to verify that a given function is a predicate, as you could do in a statically typed language. Most CL implementations provide introspection functions, such as SBCL sb-introspect:function-arglist, that let you verify that only one argument is accepted. This does not guarantee that the behavior of the function is normal, but it may be better than nothing.

+1
source

Source: https://habr.com/ru/post/1739062/


All Articles