[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proposal: count
- To: David Van Horn <dvanhorn@xxxxxxxxxxx>
- Subject: Re: Proposal: count
- From: Alexey Radul <axofch@xxxxxxxxx>
- Date: Sun, 20 Sep 2009 20:00:33 -0400
- Cc: srfi-101@xxxxxxxxxxxxxxxxx
- Delivered-to: srfi-101@xxxxxxxxxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=BiTkuCCrB7XuqOgiwDPp2v4UpayFGyDMw5OTAtmWq6A=; b=rWWxsnmK0D7b4aNW3sdmkIf9Eh+GCY/OmuTRGFP9mKqlrEbLRLMREbWUyAs5DwezRw IyRJIILL0ZcSYeNel9eyIP/xhAZzyj1vGl9dAOj/01KVg6dLLZztd0F9Q/scxW1r0Gt6 sQkj8dWj+oRuzRt3Lbg5EWWNpPCsz1s27QJK8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=o7991ummzFIUfV+LuxXUJARl9w/pv3ouTxc1AuG8sQbk1LFAOEtGBj+6/KMLnjkJZi 0BSIb1k1KBzPkVR91mM+yYFYKKX6McoFSFeeauIElj5+U7u/CdMQkLWtXwQY+qTZK8iM PsLwDrBeEhKM7svN+vToLajJoRDmLG9jI1h4M=
- In-reply-to: <4AB6B39E.3080001@xxxxxxxxxxx>
- References: <4AB6B39E.3080001@xxxxxxxxxxx>
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
>
>