Den 16.12.2010 14:48, skrev flebber:
HI
doing the pharo tutorial and I wanted to know how pharo viewed the dynamic array at index 3(seems smalltalk starts at 1 not 0)
From the xample simple enough { (2+3) . (6*6) . 'hello', ' Stef'} size. 3
from the strings example we found index by
'ProfStef' at: 1. $P
so I thought { (2+3) . (6*6) . 'hello', ' Stef'} at 3. would let me know what the array was evaluated to after execution but it doesn't. Is it confused because it doesn't know whether I want the third array element or the third character?
Led me to wonder the correct way if doing this, so that I could evaluate array 1 * 2.
{ (2+3) . (6*6) . 'hello', ' Stef'} at 1 * at 2. 180
Cheers
What do you mean? The dynamic array is created with three elements, 5 (2+3) at index 1, 36 (6*6) at index 2, and 'hello Stef' ('hello', ' Stef') at index 3. at: 3 thus returns the string. at 3 is invalid, as it is basically 2 method calls, array does not understand a message called #at, and #3 is an invalid selector anyways. For your second expression, writing ({ (2+3) . (6*6) . 'hello', ' Stef'} at: 1) * (at: 2) would not work, as you're missing the receiver for the second at: call. you'd need to do something like: array := { (2+3) . (6*6) . 'hello', ' Stef'}. (array at: 1) * (array at: 2). 180 Cheers, Henry