First time here? Check out the FAQ!
x

How to pass a variable into {...} objects?

0 votes
381 views
Hi...

I often run into this, and wondered what the correct way would be to deal with it. Something like

| index myCollection |

myCollection := #(1 2 3 4).

index := !Fader into: #( {0@0} {1@ (myCollection size)})  .

I get a variable undeclared from the compiler when it tries to access myCollection from within curly braces. How do I correctly pass a variable that has been declared outside the block or curly braces object?
asked May 24, 2015 in Capytalk & Smalltalk by cristian-vogel (Master) (8,460 points)

1 Answer

0 votes

The curly braces indicate a "literal" value—so literally, it is going to interpret what you have there as the letters of myCollection.

Instead, you could construct the collection of points.  For example:

| index myCollection |

myCollection := #(1 2 3 4).

index := !Fader into: (Array with: 0@0

                              with: (1 @ myCollection size)).

answered May 24, 2015 by ssc (Savant) (128,200 points)
...