[plt-scheme] for-each on a collection object members

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Tue Jan 8 06:53:54 EST 2008

Hi,

[Please excuse me if this is a silly question]

I want to 'map' or 'for-each' of a collection object which is a
collection of other objects, in the same way as I would over a regular
list (also filter from the list.ss List Utilities)

I can just turn the collection of objects into a list of objects, but
it seems there might be a better way? 'for-each-object-on-collection
object

  ;; collection of tuples
  (define TupleSet% (class object%
                      (define collection '())
                      (super-new)
                      ;; insert : alist -> void
                      (define/public (addTuple alist)
                        (set! collection (cons (new Tuple%
[initial-fields alist] ); tuple
                                               collection))
                        )


                      ;; getTupleCount : -> number
                      (define/public (getTupleCount)
                        (length collection)
                        )
 ... and so on ...


Should I just make up the smalltalk iterator equivalents as needed?
eg; 'do:' from smalltalk

                      ;; do : tupleMethod -> result
                      (define/public (do tupleMethod)
                        (for-each
                           (lambda (tuple) (send tuple tupleMethod) )
                            collection)
                        )

I'm searching for the 'right' way, or is this a silly question?

Cheers,

Stephen



--
Stephen De Gabrielle


Posted on the users mailing list.