[plt-scheme] for-each on a collection object members
That looks perfectly fine to me, if it is otherwise acceptable to use
lists for storing the collection. (If you needed random access or
fast search, you might consider BST's instead. In that case, you'd
have to write your own for-each.)
The reason class.ss is a macro is so that people can evolve the
design of the class system and match it to their needs.
-- Matthias
On Jan 8, 2008, at 6:53 AM, Stephen De Gabrielle wrote:
> 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
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme