[squeak-dev] Objects as Booleans (was Re: Boolean over-optimization
#ifTrue:/#ifFalse:)
Bert Freudenberg
bert at freudenbergs.de
Wed Mar 5 11:01:07 UTC 2008
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 :)
- Bert -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oooleans-bf.1.cs.gz
Type: application/x-gzip
Size: 635 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080305/e6378f51/oooleans-bf.1.cs.bin
More information about the Squeak-dev
mailing list
|