[Top][All Lists]

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

Re: [Chicken-users] Correct behavior of SRFI-1 any

From: John Cowan
Subject: Re: [Chicken-users] Correct behavior of SRFI-1 any
Date: Tue, 29 Nov 2011 01:05:23 -0500
User-agent: Mutt/1.5.18 (2008-05-17)

Nick Zarr scripsit:

> I'm writing an implementation of SRFI-1 in Javascript (just for fun) and I
> have a question about SRFI-1's any procedure.  In the docs it says that
> "(any) does not return a simple boolean (#t or #f), but a general value",
> however it also says that any must be called with a "procedure taking n
> arguments and returning a boolean result".

The latter is clearly in error: the predicate argument to ANY, EVERY,
and LIST-INDEX can return any value.  The words "and returning a boolean
result" should be removed from the specification.

> I've been testing my implementation against Chicken for correctness
> and here's what I get on Chicken:
> #;2> (any (lambda (x) (if (even? x) x)) '(1 2 3))
> #;3> (any (lambda (x) (even? x)) '(1 2 3))
> #t
> #;4> (any even? '(1 3 5))
> #f
> For #3 and #4 any correctly returns #t and #f respectively.  However for
> #2 shouldn't any return 2 instead of, what I'm assuming is, (void)?
> What is the correct behavior here?

No, that's the difference between ANY and FIND.  FIND returns the
element which satisfies the predicate, whereas ANY returns what the
predicate returns, in this case (void), because that is a true value.
Chicken is doing the Right Thing.

La mayyitan ma qadirun yatabaqqa sarmadi                            John Cowan
Fa idha yaji' al-shudhdhadh fa-l-maut qad yantahi.              address@hidden
                --Abdullah al-Hazred, Al-`Azif

reply via email to

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