4 ms·
Private state, no? class Bar def foo(baz :: Baz) ... end end def foo(bar :: Bar, baz :: Baz) ... end could be in
by akavi 11y ago
Private state, no?
class Bar
def foo(baz :: Baz)
...
end
end
def foo(bar :: Bar, baz :: Baz)
...
end
could be in this hypothetical language that the former would be allowed to access private member variables on bar = Bar.new, while the latter wouldn't.
The questions then are:
a) Is private state something we want?
b) Could private state access control be implemented in a different way (Lexically? Package level? Additional annotation?)
- kazinator 11y ago> Could private state access control be implemented in a different way The idea of friend functions of a class could be adapted from C++. It could work dynamically like this. Firstly, given obj.slot or obj.fun(); if the type of obj is not known in the given scope, then these accesses are disallowed unless slot and fun are public. Secondly, a class can be (dyamically) associated with a (dynamically extensible) list of friend generic functions. When a new method is being compiled for a generic function, the compiler uses the class information about the argument (which specializes it) to check the friend list of that class. Then inside the friend method, obj.slot and obj.fun() are allowed even if slot and fun are private. (Friendship of compiled code couldn't be revoked; once a method is processed by at least the expanding code walker, if not compiled, then it cannot lose access even if the generic function is removed from the friend list of that class.) Firstly, obj.member could be disallowed if