Skip to content

Unpacking in arglist vs inside function #51107

Open

Description

Unpacking inside the function assigns into the parent scope; unpacking in the arglist binds a new variable. Should I expect that from something in https://docs.julialang.org/en/v1/manual/variables-and-scoping/ or is that arglist-unpacking a special behavior?

let x = 1
    function f(θ)
        (;x) = θ
    end

    θ₀ = (;x=2)
    @show x # 1
    f(θ₀)
    @show x # 2
end

let x = 1
    function f((;x))        
    end

    θ₀ = (;x=2)
    @show x # 1
    f(θ₀)
    @show x # 1
end

That's on 1.9.1.

@CameronBieganek says both give 1 then 2 on 1.8.2, implying the behavior changed.

I'm not sure what's supposed to happen here.

Discourse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    needs decisionA decision on this change is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions