I’m not an expert on scope in J, so please correct me if I make a mistake. (That, in fact, is part of the reason for this question.)
What I want to do is create a name that is visible within (but not without) a locale. Note that assigning with =. does not achieve this.
I think this is impossible, but I’d love confirmation from a J expert.
After seeing Eelvex’s answer, I feel I have to clarify my question. Here’s what I want: I want a name that is global within a locale but invisible outside a locale, even if you know the name and qualify it with the locale suffix, exactly analogous to a private member of a class in OOP.
Let’s imagine a J verb called private that makes a name private within a locale.
cocurrent 'foo'
x =: 3
private 'x' NB. x is still visible to all members of _foo_, but cannot be accessed in any way outside of _foo_
bar =: 3 : 'x & *'
cocurrent 'base'
bar_foo_ 14 NB. This works, because bar_foo_ can see x_foo_
x_foo_ NB. value error. We can't see x_foo_ because it's private to the locale.
Edit, (after OP’s edit)
No, you can’t hide a name. If an entity is visible in a locale, then it is accessible from all locales. AFAIK the only names that are truly private are names defined with
=.inside an explicit:definitionPreviews answer:
All names are visible within (but not without) their locale. Eg: