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: Alex Charlton
Subject: Re: [Chicken-users] Idiomatic member? perdicate
Date: Mon, 05 Jan 2015 14:14:29 -0500
User-agent: mu4e 0.9.9.5; emacs 24.4.50.1

I’d use test-assert with member: http://api.call-cc.org/doc/test/test-assert

Bahman Movaqar writes:

> 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?
>>>


-- 
Alex




reply via email to

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