Re:A polyglot's guide to multiple dispatch
by kazinator on Thursday April 21, 2016 @01:09PM
(#11543681)
> 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.)
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