User loginNavigation |
Namespaces for methods?I'm working on adding namespaces to messages in my programming language. I've run into a few... strange... side-effects of it that I'd appreciate some feedback on. The motivation here is that since classes are open to extension, namespaces will let you add methods to existing classes while avoiding collisions. For example: // In document.mag: class Document // Stuff... end // In render.mag: def Document print() // Code to draw the document on-screen... end // In printer.mag: def Document print() // Code to send the document to a printer... end // Later... var document = Document new() document print() // Which one?
Here, the two // In render.mag: def Document render.print() // Code to draw the document on-screen... end // In printer.mag: def Document printer.print() // Code to send the document to a printer... end
You can select a specific document render.print() Or by importing the namespace: using render document print()
When it encounters a message like So, here's where you come in (I hope). There's two consequences of this that feel wrong: Dispatching a method is The fully-qualified name that's resolved for a method may be different at runtime depending on the value of the receiver. This is the part that feels really strange. Consider: class Foo def apple.method() "apple" end class Bar def banana.method() "banana" end def callMethod(obj) using apple using banana obj method() end callMethod(Foo new()) // "apple" callMethod(Bar new()) // "banana" At runtime, an unqualified name may resolve to a different namespace based on the method set of the receiver. That runs counter to my intuition of namespaces. I consider an unqualified name in a scope with an imported namespace to just be a shorthand for the one "real" fully-qualified name that it represents. This implementation doesn't work that way. Instead, an unqualified name with imported namespaces defines a set of possible names, any of which are potentially valid based on the receiver. That's a valid semantic, but one that feels unusual to me. So, questions:
Thanks! By munificent at 2011-03-10 17:54 | LtU Forum | previous forum topic | next forum topic | other blogs | 5570 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago