Local using declaration

In C++ you often do something like this:

{
    using std::begin;
    using std::end;
    std::sort(begin(x), end(x));
}

In Julia, when you have

let
    using .Iterators: take
    take([1, 2, 3], 2) |> collect
end

This will dump take into Main (“globbal namespace”) also outside of let, since using works on module scope.

I propose having a local using like in C++ that only imports symbols in the current scope (same lifetime as variables).

What do you think?

2 Likes

In Julia you can do:

let
    take = Iterators.take
    take([1, 2, 3], 2) |> collect
end
7 Likes