[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] What use, if any, is `any?' ?
From: |
Pierpaolo Bernardi |
Subject: |
Re: [Chicken-users] What use, if any, is `any?' ? |
Date: |
Wed, 5 Aug 2015 17:10:04 +0200 |
On Wed, Aug 5, 2015 at 4:11 PM, Nick Andryshak <address@hidden> 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.