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".
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? >From SRFI-1: any pred clist1 clist2 ... -> value Applies the predicate across the lists, returning true if the predicate returns true on any application. If there are n list arguments clist1 ... clistn, then *pred must be a procedure taking n arguments and returning a boolean result*. any applies pred to the first elements of the clisti parameters. If this application returns a true value, any immediately returns that value. Otherwise, it iterates, applying pred to the second elements of the clisti parameters, then the third, and so forth. The iteration stops when a true value is produced or one of the lists runs out of values; in the latter case, any returns #f. The application of pred to the last element of the lists is a tail call. Note the difference between find and any -- find returns the element that satisfied the predicate; *any returns the true value that the predicate produced*. *Like every, any's name does not end with a question mark -- this is to indicate that it does not return a simple boolean (#t or #f), but a general value.* (any integer? '(a 3 b 2.7)) => #t (any integer? '(a 3.1 b 2.7)) => #f (any < '(3 1 4 1 5) '(2 7 1 8 2)) => #t -- Nick Zarczynski Rent a Geek IT Services <http://rentageekit.com> Blog 4 <http://nickzarr.com>
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users