Saifi,
As far as I know Methods in Scala always return the last expression evaluated,
if and only if there's no explicit return
statement( Scala has return stmt)
When we dont intend to return anything , we state the result type as Unit. So
any value/ stmt last
evaluated is converted to Unit and its value is lost (Any type can be assigned
to Unit.)
>From the example,
scala> def g():Unit={
| max(3)
| def max(x:Int){
| println(x)
| }
| }
I think the error here is that we are trying to return a function defn( func
literal ? ), but it cannot be converted to Unit,
since func defn is not a Object (also, Type ?).
Regards,
Nikhil
________________________________
From: Saifi Khan <[email protected]>
To: [email protected]
Sent: Saturday, 20 June, 2009 3:03:38 PM
Subject: Re: [twincling] DEF way of evaluation
On Sat, 20 Jun 2009, Mukund Deshpande wrote:
>
> Another query is a "def" or "a method as in java" automatically returns the
> value..(No need to give explicit return) "The value evaluated recently"..So
> once it returns a value How can it again evaluate max(3) ????
> I mean how can we have two returns.
>
> thanks,
> SMS
>
There is "no" return !
The answer again lies in understanding the Functional
programming perspective.
each function is an expression,
each expression is evaluated,
each evaluation is a value !
function --> expression --> value.
So given a pattern match, the evaluated part of the function is
in effect the return value.
Does that help ?
thanks
Saifi.
Cricket on your mind? Visit the ultimate cricket website. Enter
http://cricket.yahoo.com
[Non-text portions of this message have been removed]