OR between list elements

Discussion of Common Lisp
JamesF
Posts: 98
Joined: Thu Jul 10, 2008 7:14 pm

Re: OR between list elements

Post by JamesF » Thu Jul 05, 2012 1:29 am

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.

mparsa
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

Re: OR between list elements

Post by mparsa » Thu Jul 05, 2012 2:05 am

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 :)

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: OR between list elements

Post by Goheeca » Thu Jul 05, 2012 4:28 am

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.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

mparsa
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

Re: OR between list elements

Post by mparsa » Thu Jul 05, 2012 6:22 am

yes. My bad. I used or besides identity. Now it works.
Thanks in advance.

Post Reply