Rainer Blome wrote:
You can get 90% of 'if bool then else': if: bool Then: thenClause Else: elseClause = ( bool if: thenClause False: elseClause ).
Oh, OK. In this case, a macro would indeed be an efficiency hack. Because using a message would give up locality there. Where is the `if:Then:Else:' slot? In globalBehavior, I guess. And that slot takes time to find. If its content is a normal method, it will be evaluated over and over again. Maybe the compiler can optimize that away, but I don't think so.
Well, I couldn't let *that* bait go :-) Here's a little experiment: put the if: .. method in defaultBehavior and create a test object called foo containing
(| parent* = defaultBehavior*. test: n With: x With: y = ( n do: [ x < y ifTrue: 'true' False: 'false'] ). test2: n With: x With: y = ( n do: [ if: x < y Then: 'true' Else: 'false'] ). |)
[Hint: never put such testing code in the shell, because it has a dynamic parent that can mess up performance.]
On my system, [foo test: 100000 With: 3 With: 4] time is 135..161 and [foo test2: 100000 With: 3 With: 4] time is 137..162.
No difference.
Of course, a *really* smart compiler would execute both in 0 ms, but that's another story.
-Urs
although this thread is weeks old, i feel that i owe a reply to some of the postings. sorry i didn't do so right away. i don't have the time to say all that i would like to but i tend to be a little too verbose anyway.
SPEED
rainer: >> urs: >
Maybe the compiler can optimize that away, but I don't think so.
Well, I couldn't let *that* bait go :-) Here's a little experiment: On my system, [foo test: 100000 With: 3 With: 4] time is 135..161 and [foo test2: 100000 With: 3 With: 4] time is 137..162. No difference.
i'm impressed. i should have known this outcome before, though, shame on me. seems my mind was locked on "looking up if: is not static". as you say:
[...] a dynamic parent can [will, at the moment] mess up performance.
OK, i'm a believer now.
gotta go, so procedure abstraction / BETA / CLOS is for later.
rainer
self-interest@lists.selflanguage.org