Op 25-11-2018 om 19:12 schreef dorellang:
What you want to do is:

findBasement: input2
      "solution to part1 of this challenge"

       input2 withIndexDo: [ :element :index | |action| action:=
SantaFloorAction getActionFor: element. floor := action
calculateNewFloor: floor index: index  ].
       ^ counter

Notice how I added the 'index: index' bit in the line just above the '^
counter', so you're actually performing:

action calculateNewFloor: floor index: index

If you had a method with three args you would declare it as:

methodWithArg1: arg1 arg2: arg2 arg3: arg3
    "assume this is in Foo class"
    self doSomething.

and then you would call it in another place with

...
"assume obj is some instance of Foo"
obj methodWithArg1: 'some' arg2: 'arguments' arg3: #thatMightChange
...

BTW the way you're framing the question makes me think you are not
understanding how Smalltalk works. In Smalltalk (and by extension, in Pharo)
you don't send messages to functions, you send messages to objects (all
values that you can store in variables are objects in Smalltalk). In this
context 'send message' is what in other languages is  'call the object's
instance method with some arguments'. So you may be wondering: what's a
'message' anyway? A message is a method name (or more properly in the
Smalltalk slang, its 'selector') plus some arguments. The idea is that what
actually happens when a message is received by an object depends on the
concrete implementation that that object has for that message; in other
words, the method the object has; which may vary according the class of the
object that received the message.

Actually it's not unlike other object oriented languages, but the
terminology and the syntax might be a little weird at first.

Cheers,
Diego



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



I know.
Still trying to get a feeling about it
and what takes me some time is that the use of if then is a bad smell
I try to stretch my mind around that

Roelof





Reply via email to