|
From: | Jim Ursetto |
Subject: | Re: [Chicken-users] Correct behavior of SRFI-1 any |
Date: | Mon, 28 Nov 2011 23:46:40 -0600 |
On Nov 28, 2011, at 9:01 PM, Nick Zarr wrote: I've been testing my implementation against Chicken for correctness and here's what I get on Chicken: Nick, #;2> (any (lambda (x) (if (even? x) x)) '(1 2 3)) Change that to (any (lambda (x) (if (even? x) x #f)) '(1 2 3)) or more idiomatically (any (lambda (x) (and (even? x) x)) '(1 2 3)) Your if statement returns void in the false case (technically, an unspecified value; in Chicken, it's void). But the only false value in Scheme is #f. Therefore your predicate always returns a true value for the first value it hits, so it will return void for 1. It would have returned 2 if the first value were 2: #;7> (any (lambda (x) (if (even? x) x)) '(2 3)) 2 Replacing "if" with "and" is the way we usually handle that. Jim |
[Prev in Thread] | Current Thread | [Next in Thread] |