<br><br><div class="gmail_quote">On Tue, Jun 30, 2009 at 11:28 AM, Klaus D. Witzel <span dir="ltr">&lt;<a href="mailto:klaus.witzel@cobss.com">klaus.witzel@cobss.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">
<br></div>
You just want this? result = (anObject.methodName ? methodName() : false)<br>
<br>
?</blockquote><div><br></div><div>Not quite.. if you were attempting to write it in javascript it would look more like:</div><div><br></div><div>   result = ( typeof(anObject[methodName]) == &quot;function&quot; ) ? anObject[methodName]() : </div>
<div>        currentContext == &quot;boolean&quot; ?  false : </div><div>        currentContext == &quot;number&quot; ? 0 :</div><div>        currentContext == &quot;string&quot; ? &#39;&#39; :</div><div>        currentContext == &quot;array&quot; ? [] :</div>
<div>        currentContext == &quot;object&quot; ? {} :</div><div>        undefined;</div><div><br></div><div>where currentContext would be an internal variable denoting the desired type / class / or traits</div><div>of the result.  The idea is that the defaultHandler of doesNotUnderstand would produce a reasonable</div>
<div>approximation of a result based on the semantics and context in which the call appears.</div><div><br></div><div>Here&#39;s the specific use case that I&#39;ve been fighting with... I have a virtual world in which objects can build other objects, and most objects are unique.  Any object in the world can send any other object in the world any number of messages to interact with it.  The limitations are defined in an external dictionary of valid semantic actions, but no object is likely to implement any more than 3-8 methods.</div>
<div><br></div><div>Since there is no programmer intervention in object creation, and the messages passed need not even be sensical every action requires a sane default.  The way I deal with this is subclass all of these objects from an object that has its own custom doesNotUnderstand:aMessage.</div>
<div><br></div><div>Now the problems start to arise from users.  People are more clever than objects that randomly evolve due to sexual reproduction. (surprising I know :) and often have expectations of what the words they are typing mean, independent of the implementation details under the hood.  In order to keep in line with most of these expectations, I&#39;ve hacked my doesNotUnderstand:aMessage to return false by default.  I&#39;ve been experimenting with examining the context of the call as well to return sane defaults.  My current hack is to force Boolean to respond to all of the messages various strings, and numbers, also do, and return equivalent values.</div>
<div><br></div><div>At the heart of this problem is that most professional Smalltalk programmers understand the meaning of words, the semantics of messages, in terms of their implementation semantics.  To the end user, however, their mental model is based upon the semantics of both the real world, and the virtual world that they think they understand.  Etoys made the system accessible by focusing on the user&#39;s semantics over the semantics of implementation.  Well written code that is a pleasure to read typically merges the implementation and expressive aspects of the semantics into one coherent whole.</div>
<div><br></div><div><br></div></div><br>-- <br>-=-=-=-=-=-=-=-=-=-=- <a href="http://blog.dloh.org/">http://blog.dloh.org/</a><br>