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

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Tue Jan 8 09:51:16 EST 2008

Should I, (hypothetically);

Extend class.ss macros with a way to specify a class may be
- a 'collection', with matching;
  + the data-structure to use, (List or BST)
  + and a implementation of fold(for list, or the appropriate equivalent for
BST's) (thanks Noel, very sensible advice)

I'm comfortable with extending classes, using class.ss, but I'm unsure with
extending macros, am I right in guessing that I would define a new macro
that referred to the class macro.

Would it be cheating to make a class class? (class%) then use the class
system to extend the class% class instead.

thanks,

Stephen



On Jan 8, 2008 1:00 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:

> 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
>
>


-- 
Cheers,

Stephen



--
Stephen De Gabrielle
s.degabrielle at ucl.ac.uk
Telephone +44 (0)20 7679 5242 (x45242)
Mobile                  079 851 890 45
http://www.uclic.ucl.ac.uk/annb/MaSI.html
University College London Interaction Centre
Remax House - 31/32 Alfred Place
London - WC1E 7DP

"There's an old story about the person who wished his computer were as easy
to use as his telephone.  That wish has come true, since I no longer know
how to use my telephone. " -- Bjarne Stroustrup
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080108/52001082/attachment.html>

Posted on the users mailing list.