Page 2 of 2

Re: OR between list elements

Posted: Thu Jul 05, 2012 1:29 am
by JamesF
Sorry if I gave offense; we do get a small but regular stream of people trying to outsource their homework assignments, and it's pretty unusual that a problem requires a specific function or operator, so I may have leapt to a conclusion.

You've explained the solution that you're trying to apply and that you're having trouble with, not the problem that you're trying to solve with it.
If you need to check whether one or more of the elements in the list is non-null, then any of Goheeca's suggestions will work - as long as you don't try to shoehorn #"or where it won't fit.

To ask from another angle: what behaviour is it that you need, that only the #'or operator provides?
Perhaps you could tell us what the aim of the project is? That would help us to give you more appropriate advice.

Re: OR between list elements

Posted: Thu Jul 05, 2012 2:05 am
by mparsa
No problem. But I just started to program in lisp less that 2 week ago so I don't know even the simple syntax. Remind yourself when you started to program in lisp. ;)
I also search for everything that I need but I put my question here for the best solution.
Now I define the function for what I need like this :
(defun my-or (li)
(setf k nil)
(loop for l in li collecting (setf k (or k l)))
)
It works now. But I thought maybe there is a direct solution without defining the new function.
Anyway thank you for your time :)

Re: OR between list elements

Posted: Thu Jul 05, 2012 4:28 am
by Goheeca

Code: Select all

(some #'identity (list nil nil t nil))
I think it's a direct solution. Try it again, you haven't tried it exactly this way probably and rather something like this:

Code: Select all

(some #'or (list nil nil t nil))
which is bad.

Re: OR between list elements

Posted: Thu Jul 05, 2012 6:22 am
by mparsa
yes. My bad. I used or besides identity. Now it works.
Thanks in advance.