Skip to content

outer unpacking assignment #57528

Open
@jariji

Description

@jariji

If the loop executes 0 times, then i should be 0; otherwise it should be greater than 0.

function count_and_maximum(xs)
    i = 0
    m = 0
    for (i, x) = enumerate(xs)
        m = max(m, x)
    end
    (i, m)
end
count_and_maximum(1:5) # (0, 5) is returned, not the desired result.

I want to expose i outside the loop but outer doesn't work with unpacking assignment.

           for outer (i, x) in enumerate(xs)
ERROR: syntax: no outer local variable declaration exists for "for outer"
    for (outer i, x) = enumerate(xs)
#              └──┘ ── Expected `)`

It would be nice to have some way to do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsparserLanguage parsing and surface syntax

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions