Passing multiple parameters.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing multiple parameters.

Charles Gray-3
Is it possible to pass multiple parameters to a method? Suppose I want
to have a method that solves for x in the quadratic equation, ax^2 +
bx +c =0. We know the equation is ((-b + (b*b -4*a*x) sqrt))/(2*a). I
want to pass a, b, and c to a method that might be called
quadraticSolution. This is a hypothetical question but its answer will
help me with something on which I am working.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Passing multiple parameters.

Randal L. Schwartz
>>>>> "Charles" == Charles Gray <[hidden email]> writes:

Charles> Is it possible to pass multiple parameters to a method? Suppose I want
Charles> to have a method that solves for x in the quadratic equation, ax^2 +
Charles> bx +c =0. We know the equation is ((-b + (b*b -4*a*x) sqrt))/(2*a). I
Charles> want to pass a, b, and c to a method that might be called
Charles> quadraticSolution. This is a hypothetical question but its answer will
Charles> help me with something on which I am working.

The method name reflects the number of parameters:

anObject unaryMessage. "unary message takes no parameters"
anObject + anotherObject. "binary message is punctuation, takes one parameter"
anObject takes: aParameter and: anotherParameter "keyword message"

A keyword message takes one parameter following each colon-terminated word.
In this case, the name of the message is "takes:and:".

For a solver, you'd probably have:

result := theSolver solveQuadraticEquationForA: a andB: b andC: c.

or something like that.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners