Proposal: count David Van Horn (20 Sep 2009 22:58 UTC)
Re: Proposal: count Alexey Radul (21 Sep 2009 00:00 UTC)
Re: Proposal: count David Van Horn (21 Sep 2009 00:04 UTC)
Re: Proposal: count Alexey Radul (21 Sep 2009 00:44 UTC)
Re: Proposal: count David Van Horn (21 Sep 2009 15:24 UTC)
Re: Proposal: count Taylor R Campbell (21 Sep 2009 00:51 UTC)
Re: Proposal: count David Van Horn (21 Sep 2009 14:56 UTC)

Re: Proposal: count Alexey Radul 21 Sep 2009 00:00 UTC

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 <xxxxxx@ccs.neu.edu> 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
>
>