[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

I wish find/find-if returned two values

Jim Newton

9/30/2015 8:07:00 AM

It would be great if FIND and FIND-IF returned a second value indicating whether the sought item was found or not. Otherwise it is hard to know whether NIL was the element it found.

sigh :-(

I can of course write my own, but I'd do it a bit differently anyway.
I'd provide two continuation functions, one to call with the value if found,
the other to call with no arguments if no such value is found.

3 Answers

William James

9/30/2015 8:32:00 AM

0

Jim Newton wrote:

> It would be great if FIND and
> FIND-IF returned a second
> value indicating whether the
> sought item was found or not.
> Otherwise it is hard to know
> whether NIL was the element it
> found.

I broke your lines for you.

Anyone who knows anything whatsoever about Usenet knows
that he must limit the length of his lines.

Since you are at the mercy of your Googoo master,
you know nothing whatsoever.

Gauche Scheme:

gosh> (member 9 '(2 #f 3))
#f
gosh> (member #f '(2 #f 3))
(#f 3)
gosh> (member :_ '(0 #f 9) (lambda (_ b) (not b)))
(#f 9)

--
[Jesse Jackson] would spit into the food of white patrons he hated and then
smilingly serve it to them. He did this, he said, "because it gave me
psychological gratification." -- Life Magazine, 1969-11-29

Pascal J. Bourguignon

9/30/2015 9:15:00 AM

0

Jim Newton <jimka.issy@gmail.com> writes:

> It would be great if FIND and FIND-IF returned a second value
> indicating whether the sought item was found or not. Otherwise it is
> hard to know whether NIL was the element it found.
>
> sigh :-(

Use POSITION and POSITION-IF if you care.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Kaz Kylheku

9/30/2015 2:38:00 PM

0

On 2015-09-30, Jim Newton <jimka.issy@gmail.com> wrote:
> It would be great if FIND and FIND-IF returned a second value indicating
> whether the sought item was found or not. Otherwise it is hard to know
> whether NIL was the element it found.
>
> sigh :-(

Use MEMBER or MEMBER-IF, if the sequence is a list. These return the
list's cons cell which holds the element, if it is found, otherwise NIL.
If you get a cons cell, then the element is in the CAR.

If the code has to generalize to arrays, then POSITION and POSITION-IF
get you the index of the item if it is found, whereas the not-found
case returns NIL.