As others said, a boolean is a distinct data type from a procedure that
returns a boolean. Usually the former suffices but there do exist use cases
for the latter.

Here are two examples I've seen:

1) Suppose you are unit testing filter (
http://wiki.call-cc.org/man/4/Unit%20srfi-1#filtering-partitioning ) or a
similar procedure. To be thorough, you ought to test the case where each
element of the original list is retained so the output list has the same
contents as the input list. You can get this behavior by using any? as the
predicate passed to filter.

2) Racket contracts ( http://docs.racket-lang.org/reference/contracts.html
) are defined by predicate procedures. For example, the contract for the +
procedure might be that it takes two or more arguments that each satisfy
number? and returns an object that satisfies number?. It's convenient here
to have any? (or equivalent) so you can define a contract that allows for
anything. For example the contract for number? is that it takes one object
satisfying any? and returns a boolean?.

Admittedly these cases are narrow. But they do exist. :)

Kevin Wortman

On Wed, Aug 5, 2015 at 8:10 AM, Pierpaolo Bernardi <[email protected]>
wrote:

> On Wed, Aug 5, 2015 at 4:11 PM, Nick Andryshak <[email protected]>
> wrote:
> > Hello!
> >
> > I came across this function in the official documentation recently:
> >
> > http://wiki.call-cc.org/man/4/Unit%20data-structures#any
> >
> >>any?
> >>[procedure] (any? X)
> >>Ignores its argument and always returns #t. This is actually useful
> >>sometimes.
> >
> > Is it, though? Does anyone have any practical examples? And why couldn't
> > you just replace any usages of (any? x) with just plain #t?
>
> You can indeed replace (any? x) with plain #t when any? is present in
> literal form in a call, but functions are first class objects and can
> be passed around.
>
> Suppose you have a function which searches for foos which satisfy a
> predicate in a container, like:
>
> (search-foo container predicate)
>
> If any foo will do for you, you can use it as (search-foo container any?)
>
> During the evaluation of this call to search-foo there will be a
> function application that in this particular call will be an
> application of the any? function, and that comes handy, sometimes.
>
> P.
>
> _______________________________________________
> Chicken-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to