Scope issue with begin/end

Hi,

I thought that

module MyPkg
    const b = begin
        a = 2
        b = a
    end 
end

MyPkg.b # return 2 as wantedd
MyPkg.a # return 2, but I wanted it not to exist. 

would give me a variable b with the value 2 but no variable a. But after executing this code, the binding for a exists. Is there a way i can do “precomputations” to construct an object without having them saved in the environment ? The goal is to have a package do precomputations but i do not want the package’s namespace to be polluted.

begin does not create a scope — you want to use let for that.

5 Likes

Thanks this is exactly what i wanted :slight_smile: