Hi Mukund,
I don't think the function can return two times 3,9 because you have provided 
the return type as unit ,"void" in java.So method g() can't return anything ,so 
it returns unit if I am not wrong.
Just try to do do this
val x=g()
you will notice that x is now of type g.
Reason you get 3,9 is that  inside that function you've defined another method 
and that method is called twice
and that  method "max" also return unit only ,but first it prints 3 then 
returns unit.Then it prints 9 and then returns unit finally the function "g" 
returns unit.
As far as your first question is considered...I din't understood why it was 
giving that error .
Can somebody throw light on that peculiar behaviour.
Thanks,
RajkumarGoel


________________________________
From: Mukund Deshpande <[email protected]>
To: [email protected]
Sent: Saturday, 20 June, 2009 12:27:54 PM
Subject: [twincling] DEF way of evaluation

Hi All,

scala> def g():Unit={
     | max(3)
     | def max(x:Int){
     | println(x)
     | }
     | }
<console>:6: error: block must end in result expression, not in definition
       }
       ^
Now when you see this you will expect that at the end of max block you will
have to give some expression to evaluate...but i had given it earlier.

scala> def g():Unit={
     | max(3)
     | def max(x:Int){
     | println(x)
     | }
     | max(9)
     | }
g: ()Unit

Now here i give an expression for g():Unit
scala> g
3
9

Now the answer is interesting...it  evaluates the upper expression also.Look
at the order also..Why??.


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


[Non-text portions of this message have been removed]



------------------------------------

http://twincling.org/
http://twitter.com/twincling
----------------------------------------
Yahoo! Groups Links




      ICC World Twenty20 England &#39;09 exclusively on YAHOO! CRICKET 
http://cricket.yahoo.com

[Non-text portions of this message have been removed]

Reply via email to