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)

Proposal: count David Van Horn 20 Sep 2009 22:58 UTC

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