Talk:Respond to an unknown method call: Difference between revisions

Content added Content deleted
m (→‎PicoLisp solution: copy-paste error)
Line 13: Line 13:
== PicoLisp solution ==
== PicoLisp solution ==


-- Sorry, I don't get it. The examples *do* demonstrate how to respond to an unknown message. If 'try' does not succeed, you can take any other measure you like (as here sending some other (known) message to the object). You might also call some other function on that object if you like, but that's not the point.[[User:Abu|Abu]] (moved from main page)
Sorry, I don't get it. The examples *do* demonstrate how to respond to an unknown message. If 'try' does not succeed, you can take any other measure you like (as here sending some other (known) message to the object). You might also call some other function on that object if you like, but that's not the point. [[User:Abu|Abu]] (moved from main page)
: the current solution does not respond to the unknown method call, it merely does a different call if the unknown calls fail.
: 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)
: 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)