Re:A polyglot's guide to multiple dispatch
by kazinator on Wednesday April 20, 2016 @02:05PM
(#11536398)
That's an interesting point and basically leads us to "member generic functions". An object has some static slot which is a function, and treated as a method: it can be called obj.meth(args, ...). But, this method is also a generic function. A generic function is a function; an object can have a function, and so an object can have a generic function.
You're quite right, but does it make sense to conflate objects and namespaces that way? Might it not make more sense to separate the concerns?
Re:A polyglot's guide to multiple dispatch
by kazinator on Thursday April 21, 2016 @08:01PM
(#11546192)
Object must have name spaces by definition, because they are collections of named properties.
These name spaces do not have to be conflated with program lexical scopes, whereby if you are a piece of code such and such a "blessed" function, you "see" the name space of the class as if it were lexical variable bindings.
You definitely don't want crud like different scopes in the program which are all working with exactly the same object, and want to access slot S, but they all refer to a different S because they are associated with a different place in the inheritance hierarchy, and that hierarchy contains unrelated slots named S at different levels. A given object must just have one S.
One benefit is that the name `bar` is looked up in `foo`'s namespace, which means that it doesn't have to be in the current global namespace. This is a mixed blessing, but it's sometimes what you want.