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

Proposal: count

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.


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