Namespace with lexical access

I often want to use a namespace for calculating stuff like this

FOO = 1

namespace A
x = FOO + 1
end

This is almost like a module except modules need to import names from the enclosing lexical module, which can be inconvenient. Is it possible to make a namespace where lexically prior names are accessible?

I guess you can do that as

const A = let
    x = FOO + 1
    #= some more expressions =#
    (; x, #= and other bindings you'd like to export =#)
end

The “exported” names can only be used as A.x etc., however.

1 Like