On Tue, Jul 14, 2015 at 10:47 AM, Cedric St-Jean
<[email protected]> wrote:
>
>
> On Monday, July 13, 2015 at 4:36:21 PM UTC-4, Michael Francis wrote:
>>
>> I was somewhat surprised to find that name args do not have an implicit
>> let and I don't seem to be able to embed the let syntax
>>
>> bar() = "Hello"
>> wow( ; bar = bar() ) = string( bar, " world")
>> wow()
>> : ERROR: bar not defined
>>
> This fails because you use the same name (bar) for the keyword and the
> function (see the scoping rules for keyword arguments). You can already
> achieve your goal of using keywords as "let" variables if it's named
> differently:
>
> foo() = "Hello"
> wow( ; bar = foo() ) = string( bar, " world")
> wow()
>
> This works fine (maybe we should have a convention that such variables start
> with a _?)

Well, I think the point is that this works.

```julia
julia> bar() = "Hello"
bar (generic function with 1 method)

julia> wow(bar=bar()) = string(bar, " world")
wow (generic function with 2 methods)

julia> wow()
"Hello world"
```

In general, the evaluation of keyword is quite special (scope, order
etc.) and should probably be "fixed" someday.

Ref: https://github.com/JuliaLang/julia/issues/9535

Reply via email to