[Newbies] Passing multiple parameters.
Randal L. Schwartz
merlyn at stonehenge.com
Sat Sep 13 01:21:25 UTC 2008
>>>>> "Charles" == Charles Gray <tcykgreis at gmail.com> 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
<merlyn at stonehenge.com> <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
More information about the Beginners
mailing list