Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

RE : perform

New Message Reply Date view Thread view Subject view Author view

Subject: RE : perform
From: Christophe Le Page (christophe.le_page@cirad.fr)
Date: Tue Apr 20 2004 - 13:31:17 CEST

 
Hi Joelle,
 
Good guess, you have to use #perform:with:
The first argument of that method is the selector name, which is a
symbol ending by the character ':'
The second one is the value to be used as the argument of the selector
name.
 
In your case, it gives:
    1 to: 10 do: [:i | self perform: ('var', i printString, ':')
asSymbol with: 100]
 
This is a concise way to write:
    self perform: #var1: with: 100.
    self perform: #var2: with: 100.
    ...
    self perform: #var10: with: 100
 
And this is strictly equivalent to:
    self var1: 100.
    self var2: 100.
    ...
    self var10: 100
    
 
clp
 

-----Message d'origine-----
De : owner-cormas@cirad.fr [mailto:owner-cormas@cirad.fr] De la part de
Joelle Noailly
Envoyé : mardi 20 avril 2004 09:26
À : cormas
Objet : name variables with printString

Hi everyone,

Thank you Bruno for answering my questions about collections so quickly!
It works fine!

I actually have another question for the Cormas forum. I have a set of
10 variables called var1, ... var10. I want to associate values to these
variables using a loop. I thought of writing something like:
1 to: 10 do: [:i | self ('var', printString i): 100]
but this does not seem to work. Should I use a perform command or
something like that?
Thanks for your help,

cheers,
Joelle Noailly

Bruno Locatelli wrote:

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