Ticket #31 (new enhancement)

Opened 16 years ago

make sets sequences

Reported by: dherman Owned by: dherman
Priority: major Milestone:
Component: dherman/set.plt Keywords:
Cc: Version:
Racket Version:

Description

Mark Engelberg wrote:

I thought you might be interested to know that if you add the
following to set.plt, then sets become compatible with sequences and
can be used inside of for loops.

(define (set->seq s)
  (make-do-sequence
   (lambda ()
     (let-values ([(more? next) (sequence-generate (in-hash-keys
(set-elts s)))])
       (values (λ (i) (next))
               (λ (i) (more?))
               (more?)
               (lambda (i) i)
               (lambda (v) #t)
               (lambda (i v) #t))))))

(define-struct set (elts)
  #:property prop:custom-write (lambda (set port write?)
                                 (write-hash "set" (set-elts set) port write?))
  #:property prop:sequence set->seq)
Note: See TracTickets for help on using tickets.