Question: interrogating a method's arguments

Brent Pinkney pinkney_b at aircom.co.za
Tue May 20 06:47:14 UTC 2003


Richard,

>Let's suppose the method is
>    foo: x bar: y ick: z ack: u uck: v
>Now, let's get those things in an array.
>	a := {x. y. z. u. v}.
>
> ....

I am well aware of how to convert a bunch of objects into an Array. This was not however the question. But thank you anyway.

>	a := {x. y. z. u. v}.
>	i := a findFirst: [:x | x isZero not].
>	sign := i = 0 ifTrue: [0] ifFalse: [(a at: i) sign].
>	a := sign >= 0 ifTrue: [a abs] ifFalse: [a abs negated].
>	"Proceed with the revised arguments in a."

I am also quite capable of making all elements of array have the same sign. This too was not the question. But thank you again.

>The LEAST of your problems is getting the arguments into an array.
Nope - that is pretty much my problem. 

>Note that since method arguments are read-only in Smalltalk,
>there is no forgiveable way to change them; you have to proceed
>with the revised argument values stored somewhere else, which
>might as well be an array.

I apologise for my grotty example, which did modify the arguments of my hypothetical Foo class. MY real life problem does indeed collect them into another array.

Yet again, that was not the question I posed.

>Yeah, well trying to change method parameters doesn't count as
>"elegant" in Smalltalk, it counts as "deeply depraved and disturbed".
>And using reflective machinery (thisContext arguments, should it ever
>exist) just to pick up a few arguments and make an array of them is
>DEFINITELY "beating the problem to death with a stick".  

Again, my question was how to get the arguments into an array. What I plan to do with them is a separate problem. 

>I mean, it's not as if it's hard to make an Array, or anything.
>
>Maybe because turning the arguments into an Array is just so
>forehead-smacking *easy* just the way things are already?

Ah yes, it is fore-head smackingly easy to convert the arguments of the CURRENT method into an Array, however, pray tell how you would get the arguments for any method in your calling chain ?

>Not me.  The problem as stated is trivially solved without it, and it doesn't solve any other >problems anyone has reported.	
Nope, you reduced my question to a trivial example, and then solved that.

Nevertheless, surely it is my responsibility to factor out this functionality, so that should anyone else need it, there it is ? No ?

Regards

Brent



More information about the Squeak-dev mailing list