[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: the FIND function applied to cons cells

William James

10/25/2015 8:53:00 PM

Pascal Bourguignon wrote:

> > Is there any common function or idiom which is similar to MEMBER-IF
> > but applies its testing function to the cons cell rather than the top
> > level
> > item?
>
> Well, you can scan the extensive list of sequence functions at:
> http://www.lispworks.com/documentation/HyperSpec/Body/c_...
> and perhaps also the cons functions at:
> http:///www.lispworks.com/documentation/HyperSpec/Body/c_conses.htm
>
> But I guess the answer is: No.
>
> > I'd like to do the following
> >
> > (on-member-if #'(lambda (sub) (eqv 5 (cadr sub)))
> > '(1 2 3 4 5 6 7 8))
> > ===> (4 5 6 7 8)
> >
> > The function would be easy to write using LOOP, but for completeness it
> > would be nice if it took all the same arguments as the MEMBER family of
> > functions.
>
> The closest that can be used is maplist, but it conses a partial
> result list which is discarted in:
>
> (block :done
> (maplist (lambda (rest)
> (when (eql 5 (second rest))
> (return-from :done rest)))
> '(1 2 3 4 5 6 7 8 9)))
> --> (4 5 6 7 8 9)

Gauche Scheme:

(use util.match)

(let recur ((xs (iota 9 1)))
(match xs
([a 5 more ...] xs)
([] #f)
([a more ...] (recur more))))

(4 5 6 7 8 9)

--
As Helle "Hamas" Klein, political editor of Sweden's largest newspaper
Aftonbladet, boasts: "If the debate is going to be about whether there are
problems with immigrants, we don't want it". Welcome to Sweden, the country
where the media doesn't even pretend to champion freedom of speech, but openly
brags about censorship.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html