[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squeak-dev
Subject:    [squeak-dev] Re: sane defaults and doesNotUnderstand: (was Future
From:       "Klaus D. Witzel" <klaus.witzel () cobss ! com>
Date:       2009-06-30 21:05:54
Message-ID: op.uwcvj4zjrf0v61 () toshiba19
[Download RAW message or body]

On Tue, 30 Jun 2009 18:24:21 +0200, David Goehrig wrote:

> On Tue, Jun 30, 2009 at 11:28 AM, Klaus D. Witzel wrote:
>>
>> You just want this? result = (anObject.methodName ? methodName() :  
>> false)
>>
>> ?
>
>
> Not quite.. if you were attempting to write it in javascript it would  
> look more like:
>
... understood ...
>
> where currentContext would be an internal variable denoting the desired  
> type / class / or traits of the result.

Can you put a method #defaultValue to the class side of String, Number,  
etc, similiar to #defaultElement that is already in the collection  
hierarchy. Then, assuming you have the below in control of  
#doesNotUnderstand:, messages like

	x zork

would return (thisContext client class defaultValue). But your  
currentContext, that's not easy to find out, even if you know what  
thisContext client is.

>  The idea is that the defaultHandler of doesNotUnderstand would
> produce a reasonable
> approximation of a result based on the semantics and context in which
> the call appears.
>
> Here's the specific use case that I've been fighting with
...

You can make your own defaultHandler of #doesNotUnderstand:, like this,  
during your computation:

  [myObject myComputation]
   on: MessageNotUnderstood
   do: [:ex | ex return: ex receiver class defaultValue]

So ('' zork) will return ('' class defaultValue),
and (123 zork) will return (123 class defaultValue), etc.

?

/Klaus



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic