The return value of the function is value of the last expression evaluated. For assignment, the right-hand side is always returned. So in `f` you get the value x*2.0 returned which is 2.0.
On Wednesday, September 16, 2015 at 3:41:22 PM UTC-4, ggggg wrote: > > I was playing around with type declarations and came across an > counterintuitive result. I'm not sure if this is the intended behavior or > not, but it certainly surprised me. > > Consider the functions > > *function f(x)* > > *y::Int* > > *y=x*2.0* > > *end* > > *function g(x)* > > *y::Int* > > *y=x*2.0* > > *y* > > *end* > > *julia> **f(1),g(1)* > > *(2.0,2)* > > I expected them to behave identically, always returning an Int. But > clearly f returns a Float64. > > > It seems like in the presence of the type delaration y=x*2.0 is > interpreted as > > temp=x*2.0 > > y=Int(temp) > > temp > > is that right? >
