(I deleted the previous post since the formatting of the IJ notebook went 
all screwy in google groups, so I'll post it again as .png)

Thanks for the reply, but it isn't the function that is the problem 
(whitespace shouldn't matter either).

Let me state the problem more clearly, in the global scope why can't I 
specify a variable using the ::TypeName syntax? So for example I have an 
undefined name y that I want to be Float64:

<https://lh6.googleusercontent.com/-JGrT2o5ozFI/U4562atOYAI/AAAAAAAAAL8/56UWMArI-aA/s1600/Screen+Shot+2014-06-04+at+9.44.19+AM.png>
But when you are in a function scope exactly the same syntax works just 
fine:

<https://lh3.googleusercontent.com/-Ko_eJsu593M/U457hk8aIvI/AAAAAAAAAMU/-2MJSTEBM8Y/s1600/Screen+Shot+2014-06-04+at+9.50.40+AM.png>
Is there some obscure reason that the global scope is somehow special when 
it comes to handing the types of variables?



On Wednesday, June 4, 2014 12:13:30 AM UTC+8, Mauro wrote:
>
> That should work.  This works for me: 
>
> julia> function f(x) 
>        y::Float64 = 4.5 
>        y = x + 5 + y 
>        return y 
>        end 
> f (generic function with 1 method) 
>
> julia> f(5) 
> 14.5 
>
> However, there are some subtleties, have a look at the manual 
> http://docs.julialang.org/en/latest/manual/types/ 
>
> (The preferred style, I think, is not leave no space between a function 
> name and (...).) 
>
> On Tue, 2014-06-03 at 08:48, [email protected] <javascript:> wrote: 
> > I'm new to Julia, and it is looking very promising. I like how you can 
> > specify the type of a function argument by using ::TypeName after the 
> name, 
> > so for example: 
> > 
> > myfunc (x::Float64) 
> > 
> > As this make the variable name more prominent when looking at the code 
> > since it comes first. I naturally went to use this syntax elsewhere in 
> the 
> > body of a function: 
> > 
> > x::Float64 = 2.3 
> > 
> > but it doesn't work, and I had to use 
> > 
> > x = float64 (2.3) 
> > 
> > is there a reason not to support the function argument way of specifying 
> > the type of a variable? 
>
>
>

Reply via email to