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:
In [1]:
typeof(y)
y not defined
while loading In[1], in expression starting on line 1
In [2]:
y::Float64 = 4.2
y not defined
while loading In[2], in expression starting on line 1
Why is this not possible in the global scope but it is possible inside a
function like this:
In [3]:
function func()
y::Float64 = 4.2
return y
end
typeof(func())
Out[3]:
Float64
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?
>
>
>