[squeak-dev] Objects as Booleans (was Re: Boolean
over-optimization #ifTrue:/#ifFalse:)
Igor Stasenko
siguctua at gmail.com
Wed Mar 5 11:44:31 UTC 2008
On 05/03/2008, Bert Freudenberg <bert at freudenbergs.de> wrote:
> On Mar 5, 2008, at 7:52 , Lukas Renggli wrote:
>
> >> So, the only way is to compile method without optimization of
> >> #ifTrue #ifFalse:,
> >> to make sure they do real sends?
> >
> > Just today in my blog-reader:
> >
> > http://www.cincomsmalltalk.com/userblogs/mls/blogView?
> > showComments=true&printTitle=Boolean_Objects&entry=3382109971
> >
> > This should also work in Squeak.
>
> Hehe, very cool. It works a bit differently in Squeak, where the
> image code has to rewind the context before the jump bytecode that
> recognized the non-boolean. Attached is a little changeset that adds
> #asBoolean to various classes and overrides #mustBeBooleanIn: to use
> that, provided objectsAsBooleans has been enabled. File in, then try
> this:
>
> Preferences enable: #objectsAsBooleans.
> #(0 1 nil #() #(a b c) 'hi' '') collect: [:each |
> each -> (each ifTrue: ['yes'] ifFalse: ['no'])]
>
> #(0->'no' 1->'yes' nil->'no' #()->'no' #(#a #b #c)->'yes' 'hi'->'yes'
> ''->'no')
>
> Fun indeed :)
>
Yeah, rewinding a bytecode counter of parent context is a kind of
woodo black magic. But hey! It works!
>
> - Bert -
>
--
Best regards,
Igor Stasenko AKA sig.
More information about the Squeak-dev
mailing list
|