[Newbies] perform withArguments

Bert Freudenberg bert at freudenbergs.de
Tue Apr 24 18:32:38 UTC 2012

On 24.04.2012, at 10:59, Dawson wrote:

> .. I had thought there might be a way of "building up" the "cellObject
> cellLock: aBoolean" ... judging from the replies, it seems that it is
> either a) crazy, b) it can't be done, c) no one knows how to do it.

It's a) crazy.

Of course there's a way to do it. It depends on where your variables actually are. For temporary variables, you would use thisContext.

| cell1 cell2 cell3 |
cell1 := 'this'.
cell2 := 'is'.
cell3 := 'crazy'.
ctx := thisContext.
(1 to: 3) inject: '' into: [:s :i | s, (ctx at: i), ' ']

For instance variables, you would use "instVarNamed:"

cell1 := 'this'.
cell2 := 'is'.
cell3 := 'crazy'.
(1 to: 3) inject: '' into: [:s :i | s, (self instVarNamed: 'cell', i asString), ' ']

Both of these are equally crazy. An array is much less crazy:

cell1 := 'not'.
cell2 := 'so'.
cell3 := 'crazy'.
array := {cell1. cell2. cell3}.
array inject: '' into: [:s :cell | s, cell, ' ']

But as others pointed out, in real code you would not even put cells into individual variables in the first place, but create them as an array (not OrderedCollection, since you do not need the number of cells to change).

- Bert -

More information about the Beginners mailing list