[Newbies] perform withArguments

Dawson abu_joseph at yahoo.com
Tue Apr 24 13:19:39 UTC 2012


Hi,

actually, that is not quite what we want to do (we meaning my son and I
in our first squeak project).

Since we were unable to assemble the message, we ended up doing a
brute force method to get it to work:

lockCell: aBoolean row: aRow column: aColumn

	self addressToCellNumber: aRow and: aColumn
	"this converts the big grid aRow, aCoulumn into a cellNumber"
	
	(aBoolean isKindof: Boolean)
	  ifTrue: [
		   (cellNumber =1) ifTrue: [cell1 cellLock:aBoolean].
		   (cellNumber =2) ifTrue: [cell2 cellLock:aBoolean].
		   (cellNumber =3) ifTrue: [cell3 cellLock:aBoolean].
		   (cellNumber =4) ifTrue: [cell4 cellLock:aBoolean].
		   (cellNumber =5) ifTrue: [cell5 cellLock:aBoolean].
		   (cellNumber =6) ifTrue: [cell6 cellLock:aBoolean].
		   (cellNumber =7) ifTrue: [cell7 cellLock:aBoolean].
		   (cellNumber =8) ifTrue: [cell8 cellLock:aBoolean].
		   (cellNumber =9) ifTrue: [cell9 cellLock:aBoolean].
		].

As you can see that is really repetitive. So, it seemed to us that one
should be able to dynamically build the message in one line,

that is why we tried to do something like:

 self perform: ('cell', cellNumber asString) asSymbol ... to build up
the "cell1 ... cell9" object. But we couldn't figure out how to build up
the rest of the message.

(One solution which is possible was presented by Louis Labranda which
involves using an ordered collection ... that should work fine ... but
is there no way of building up the message similar to our attempt, but
expanding on it?  We thought that everything's an object in Squeak ...
what happened to that?)

Thanks,

Dawson (I'm the under 15 year old's father, and I don't mind my name
being published)






On 24/04/12 7:59 AM, Bert Freudenberg wrote:
> So if I understand correctly you want to do something equivalent to this:
> 
> 	cell1 cellLock: true.
> 	cell2 cellLock: true.
> 	cell3 cellLock: true.
> 	... etc ...
> 
> Yes? If so, then perform is not what you are looking for. Perform lets you assemble the message selector, but not the receiver of the message. The Right Way to do this would be to have an Array of cells. Arrays are a collection of objects, and individual objects can be accessed by index. So if "cells" was an array of your cell objects, you could write
> 
> 	(cells at: 1) cellLock: true.
> 	(cells at: 2) cellLock: true.
> 	(cells at: 3) cellLock: true.
> 	... etc ...
> 	
> but also iterate over all of them:
> 
> 	1 to: 10 do: [:i | (cells at: i) cellLock: true]
> 
> Does that make sense?
> 
> - Bert -


More information about the Beginners mailing list