Question

is there a function like find in lisp that returns true instead of the element we're trying to find?

example:

I want it to do

(find 'x '(a c x)) = t

not

(find 'x '(a c x)) = x

Also, the reason I am asking is because I am trying to reach the deepest element in a list. My plan was to flatten the list every time i recursively called it.

I would then stop the recursive call when

(mapcar 'atom list)

would tell me every atom in there is true.

Do you believe this is a good approach to this problem?

Was it helpful?

Solution

There's no such function, but it can't be easier to write one:

(defun find-t (&rest args)
  (when (apply #'find args)
    t))

Also instead of (mapcar 'atom list) you can use (every #`(eql t %) list), i.e. check that every item in list is exactly t. (Here #`() is syntactic sugar for one-argument lambdas, that I use.)

But overall it's unclear, what you're trying to achieve with all this. Can you elaborate on what you're trying to do?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top