No, the difference in scope is for the right side of the = sign.

Default parameters is only fancy syntax for declaring multiple methods at 
once.

function foo(x, z = a)
## calculation using x and z
end

is equivalent to

function foo(x,z)
## calculation using x and z
end

foo(x) = foo(x, a)

In the second definition `a` is accessed as a global variable, but when `a` 
is a immutable and constant, you don't have to care.

Ivar

kl. 10:41:21 UTC+2 onsdag 2. april 2014 skrev Oliver Lylloff følgende:
>
> Are the default values then considered in a global scope? Not sure I fully 
> understand the doc: 
> http://docs.julialang.org/en/latest/manual/functions/#evaluation-scope-of-default-values<http://www.google.com/url?q=http%3A%2F%2Fdocs.julialang.org%2Fen%2Flatest%2Fmanual%2Ffunctions%2F%23evaluation-scope-of-default-values&sa=D&sntz=1&usg=AFQjCNELUu0GRf8NxNeQf_gBKlrqUwqXYw>
>
> function foo(x,z=1)
>     ...    # z in global scope?
> end
>
> function foo2(x) 
>     z=1     # Local scope
>     ...
> end
>
> - Oliver
>
> Den tirsdag den 1. april 2014 17.26.45 UTC+2 skrev Steven G. Johnson:
>>
>> Note that default arguments in Julia can simplify this further.  Often 
>> you have Matlab code like
>>
>> function y = foo(x, z)
>>      if nargin < 2
>>          z = ...default value...
>>      end
>>      ....
>> end
>>
>>
>> Which in Julia can be simplified to
>>
>> function foo(x, z = ...default value...)
>>     ...
>> end
>>
>>  
>> This is equivalent to declaring two functions, foo(x,z) and foo(x) = 
>> foo(x, ...default value...)
>>
>

Reply via email to