chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Idiomatic member? perdicate


From: Bahman Movaqar
Subject: Re: [Chicken-users] Idiomatic member? perdicate
Date: Mon, 05 Jan 2015 22:39:38 +0330
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 01/05/2015 10:26 PM, Alex Charlton wrote:
> Just use member. Member returns #f when the element is not contained in the 
> list. Your first function will never return #f, since member never returns an 
> empty list.

My mistake. This naive question actually popped up when I was writing
tests...the following will fail where it should pass because "test"
expects an identical value to pass.
  (test #t (member a-thing list-of-things))
So how would you go around this?

>
> Bahman Movaqar writes:
>
>> I need to check if a list contains an element. There are 2 approaches as
>> far as I could gather:
>>
>>   A: (define (member? e l) (not (null? (member e l))))
>>   B: (define (member? e l) (any (lambda (x) (equal? x e)) l)) ;; using
>> srfi-1
>>
>> Which one do you seasoned CHICKEN'ers recommend in terms of performance
>> and being idiomatic?
>>

-- 
Bahman Movaqar

http://BahmanM.com - https://twitter.com/bahman__m
https://github.com/bahmanm - https://gist.github.com/bahmanm
PGP Key ID: 0x6AB5BD68 (keyserver2.pgp.com)


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]