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

Re: SRFI 121: Generators

This page is part of the web mail archives of SRFI 121 from before July 7th, 2015. The new archives for SRFI 121 contain all messages, not just those from before July 7th, 2015.



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        cowan@xxxxxxxx
A mosquito cried out in his pain,
"A chemist has poisoned my brain!"
The cause of his sorrow / Was para-dichloro-
Diphenyltrichloroethane.                                (aka DDT)