From: Dan Sugalski Date: 2003-01-06T11:15:48+09:00 Subject: Re: Compile time constant folding? At 10:32 AM +0900 1/6/03, Joel VanderWerf wrote: >Dan Sugalski wrote: >>It's not like this is expensive in the simple case, but when you do >>something like: >> >> (1 / sin(2.3)) * log(4) >> >>in a loop, well, that can add up pretty quickly. > >And in this case we have to assume that sin and log are pure >functions, in addition to assuming that they will never be >redefined. Sure, you can make sin and log special cases, but where >do you stop? Never! Never I say--first constant expressions, next the world! Bwahahahahaha! Erm. Sorry, nevermind... :) >Anyway, why would one have such a complex expression within a loop? It's not uncommon to have expressions that look non-constant that turn out to really be constant once surrounding code's analyzed. > It's not like in C where an apparently simple expression can be >expanded by the preprocessor into something that needs a lot of >folding. The complexity of the expression is apparent in the ruby >code, and it is telling you to move it out of the loop. You'd be surprised. Anyway, Matz's spoken, so I'm set now. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk