[plt-scheme] generic programming in plt scheme

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Sun Apr 25 02:18:46 EDT 2010

In my experience, PLT Scheme is not generally written in a way that
makes it easy to define generic operations over multiple datatypes,
however, in this case you're in luck.  You can use the sequence
abstraction:

(define (generic-length l)
  (for/fold ([len 0]) ([element l]) (add1 len)))

Works on lists, vectors, strings, and user-defined streams (that
implement the sequence abstraction).

See sequence in the help desk for more info.

On Sat, Apr 24, 2010 at 11:05 PM, Skeptic . <skeptic2000 at hotmail.com> wrote:
>
> Hi,
> What would be the idiomatic way of defining a generic length procedure over,
> let's say lists, vectors, strings and user-defined streams, in PLT Scheme ?
> Thanks.
>


Posted on the users mailing list.