Re: SRFI 121: Generators cowan@xxxxxx 24 Feb 2015 14:50 UTC

Kevin Wortman scripsit:

> OK, so this should be explicitly defined somewhere right? A programmer
> needs to know what data types they may safely assume will work. I imagine
> that for the purposes of this SRFI, "collection" may be any of list,
> vector, bytevector, string, or generator.

No, it can be anything with a for-each function with the right
signature.  A positive integer is a collection, given this function:

(define (integer-for-each proc n)
  (let loop ((n n))
    (unless (= n 0)
      (proc (remainder n 10))
      (loop (quotient n 10)))))

I'm not sure how best to explain this.  Suggestions, anyone?

> Well if a sequence has duplicates then it isn't really a mathematical set,
> and the conventional definition of set union, etc. does not work. It's
> then
> unclear whether these are actually multiset operations, where duplicates
> should be retained in the output; or whether they are set operations, and
> duplicates should be filtered out of input before performing the
> conventional set operations.

You're right, it is unclear.  Given the existence of a generator
operation for deleting neighbor duplicates, we might as well assume
that there are none.

> A less important consideration is that handling duplicates takes some
> effort, so these procedures can be faster if they are free to assume that
> inputs have no duplicates.

Good point.  I'll revise accordingly.

--
John Cowan          http://www.ccil.org/~cowan        xxxxxx@ccil.org
A mosquito cried out in his pain,
"A chemist has poisoned my brain!"
The cause of his sorrow / Was para-dichloro-
Diphenyltrichloroethane.                                (aka DDT)