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

Re: Proposal: count



My only worry is that the name 'count' clashes with a traditional name
for a procedure that counts the number of elements of a collection
that satisfy some predicate (and could therefore be confusing, in
addition to causing actual name collisions).  I do not, however, have
a concrete suggestion for doing better.

~Alexey

On Sun, Sep 20, 2009 at 6:58 PM, David Van Horn <dvanhorn@xxxxxxxxxxx> wrote:
> While `length' gives you number of pairs in a list, it's also useful to
> determine the number of pairs in a (potentially) improper list.  Since an
> efficient implementation of this procedure cannot be defined outside the
> random-access library, I propose adding the following procedure.
>
> Unless there are objections, I will add this to the next revision of the
> SRFI.
>
> David
>
>
> procedure: (count obj) -> k
>
> Returns the number of pairs in the chain of pairs, obj.  When given a list,
> this procedure returns a result equivalent to (length obj).  This operation
> must take time bounded by O(log k).
>
> (count '(a b c))       => 3
> (count '(a (b) (c)))   => 3
> (count '(a b . c))     => 2
> (count '())            => 0
> (count 5)              => 0
>
>