Author | Message |
---|---|
Vanquish39
Posts: 134
|
Posted 17:25 Sep 21, 2012 |
Are any of you having problems nesting functions? Every time I nest a function and call the outer function, it always returns (), an empty list. Any of you having this problem as well? Here is an example that should return 5 but returns ()
def getHypo(a: Double, b: Double) = { getRightSide(a, b);
def getRightSide(a: Double, b: Double) = {
Math.sqrt( (a*a) + (b*b) );
}
}
getHypo(3,4) returns ()
If I un-nest the functions, it works fine.
Last edited by Vanquish39 at
17:27 Sep 21, 2012.
|
toramoss
Posts: 13
|
Posted 18:32 Sep 21, 2012 |
I think you need to define your method before you call it, if you switch it around like so:
def getHypo(a: Double, b: Double) = {
def getRightSide(a: Double, b: Double) = {
scala.math.sqrt( (a*a) + (b*b) );
}
getRightSide(a, b);
}
This should give you an answer |
Vanquish39
Posts: 134
|
Posted 20:49 Sep 22, 2012 |
Thank you! |