Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: collections

New Message Reply Date view Thread view Subject view Author view

Subject: Re: collections
From: Bruno Locatelli (blocatel@catie.ac.cr)
Date: Mon Apr 19 2004 - 21:40:09 CEST

Hi Joelle,

> I am trying to create a collection of individual collections. For
> instance, I have a series of n elements, each one composed of 5 objects
> as follows: element_1={a, b, c, d, e}, element_2= {b, c, d, e, a}, ...
> element_n={e, e, d, c, a}.
> Now, I want to combine all these elements into a big collection of the
form:
> Coll={element_1, element_2, ..., element_n}.

If you write the following code, you will
create a "myBigCollection" containing collections.

myBigCollection := OrderedCollection new.
anElement1 := OrderedCollection new.
anElement1 add: #a.
anElement1 add: #b.
anElement1 add: #c.
anElement1 add: #d.
anElement1 add: #e.
myBigCollection add: anElement1.
etc...

> The tricky part is that I also would like to ask the program to browse
> through the big collection. For instance, check if the element
> corresponding to {b,c,d,e,a} is in the big collection, and if yes,
> delete it.

You can work with your "big collection", as you do with any collection.
For instance, to remove an element:

searchedElement := OrderedCollection new.
searchedElement add: #b.
searchedElement add: #c.
searchedElement add: #d.
searchedElement add: #e.
searchedElement add: #a.
myBigCollection remove: searchedElement ifAbsent: [ ]

Another example: if you want to select the elements that contain 'a' as a
first symbol:

myBigCollection select: [:e | e first = #a]

Suerte!
Ciao
  bruno
_____________________________

Bruno Locatelli
Global Change Group / Grupo Cambio Global
CIRAD Forêt (www.cirad.fr) - CATIE (www.catie.ac.cr/cambioglobal)
Apdo 2, Turrialba 7170
Costa Rica

Tel: 506.558.22.16
Fax: 506.556.62.55
Email: bruno@melix.org
Web perso: http://www.locatelli1.net
________________________________

New Message Reply Date view Thread view Subject view Author view
 

Back to home