List Info

Thread: Program flow




Program flow
user name
2006-08-10 22:33:07

On Thu, 10 Aug 2006 11:16:25 -0700, Steve Dekorte wrote:
> On 9 Aug 2006, at 04:55 pm, Dendik wrote:
>> switch := Map clone atPut("1", block(1 print)) atPut("2", block(2
>> print))
>> switch at(x asString) call
>>
>> There probably are still some issues with performance either: we
>> need the
>> Map object to only be created once and also block calling is
>> probably not
>> so efficient, also, I'm not sure, which way of using Map is best for
>> performance...
>
> One trick is to embed the Map value in the message tree of the method.
>
> Example:
>
> Object embedValue := method(e, call message setCachedResult(e); e)
>
> Now we can do:
>
> switch := embedValue(Map clone atPut("1", block(1 print)) atPut("2",
> block(2 print)))
> switch at(x asString) call
>
> And the map will only be created the first time it executes.
>
> We can also replace the blocks with messages and eval them directly:
>
> switch := embedValue(Map clone atPut("1", message(1 print)) atPut
> ("2", message(2 print)))
> doMessage(switch at(x asString))
>
> which avoids the overhead of creating a context for the block.
>
> These patterns could be implemented in a single switch() method. And
> to avoid the overhead of calling it, it could even inline itself (by
> modifying the message tree of the caller) the first time it's called.
>
> - Steve

Thanks, Steve, I'll play around with it. Looks like you've answered all my
questions at once

Danya

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )