gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

Who can catch `NoSuchMethod` #114

Open apblack opened 8 years ago

apblack commented 8 years ago

In Smalltalk, when a non-existant method is requested, the target object hets a chance to handle the condition, before the default system error handler. In Self, I think that the process making the request gets the first chance to handle the error, followed by the target object.

In Grace, NoSuchMethod is raised in the requester; the target object gets no say. This makes it hard to create stuff like RPC proxies, or the magic wrapped dom objects that expose HTML5 Canvas methods in JavaScript.

Should we allow objects to implement

method noSuchMethod (requester, requestedMethodName, arguments) -> Unknown

if they wish, and execute such a method (if it exists) before raising the NoSuchMethod exception?

kjx commented 8 years ago

no.

DoesNotUnderstand It's a very significant base-level change to the language that makes it an awful lot more powerful (and once you go there, almost impossible to type). We shouldn't put that into the base language: if we need it --- and for some things, perhaps we do --- then it should go in as an explicitly reflexive facility. Yes that makes it harder to use reflexive method definitions: that's the point.

Self sends DoesNotUnderstand (called "undefinedSelection:...") to the receiver, like Smalltalk and intentionally for the same reasons, but if that send also is undefined then it notifies the process (rather than looping I guess).

apblack commented 8 years ago

I agree that this is a reflexive facility. Can you make a concrete suggestion as to how it should appear? Is the import of your comment that the receiver should request

 mirror.reflect(self).onNoSuchMethodDo { methodName, arguments  -> ... }

rather than defining

method noSuchMethod (methodName, arguments) { ... }

Or are you saying something else?