Anonymous user
Talk:Respond to an unknown method call: Difference between revisions
Talk:Respond to an unknown method call (view source)
Revision as of 11:58, 7 November 2011
, 12 years ago→PicoLisp solution
m (→PicoLisp solution: copy-paste error) |
|||
Line 13:
== PicoLisp solution ==
: the current solution does not respond to the unknown method call, it merely does a different call if the unknown calls fail.
: a correct solution would let the call <code>(try 'message1> Obj)</code> be successful. and actually it shouldn't even need to use <code>(try)</code>, but it should be possible to directly call <code>(message1> Obj)</code> without error.--[[User:EMBee|eMBee]] 08:37, 7 November 2011 (UTC)
:: No, it is not the case that the unknown call "fails" in the examples. Instead, his is a controlled behavior, and exactly the purpose of 'try'.
:: There are three ways to send a message to an object in PicoLisp: (message1> Obj), (send 'message1> Obj) and (try 'message1> Obj). The standard way, (message1> Obj), is just a convenient abbreviation of (send 'message1> Obj). They all three do a dynamic search for a definition of 'message1>' in Obj and its (super)classes. If a method definition is found, it is executed in the context (i.e. 'This') of Obj. If no such method is found, the case must be handled explicitly (what else?). And that's what 'try' is for, because the direct call and the one with 'send' throw an error.
:: So 'try' is the "primitive" form of 'send', which allows you to roll your own special method invocation, like calling (try 'unknown> Obj), and handling it yourself. Then calling some other function or method is the only way for the object to "respond (sensibly/usefully)". Not that an object can never "respond" all by itself, there must always be some function call involved (explictly or implicitly). --[[User:Abu|Abu]] 00:55, 7 Nov 2011 (UTC)
|