From: Mark Probert Date: 2003-01-07T00:24:21+09:00 Subject: Re: Compile time constant folding? At 10:08 AM 1/6/2003 +0900, Dan wrote: >At 9:19 AM +0900 1/6/03, Mark Probert wrote: >>Dan Sugalski wrote in comp.lang.ruby: >>> >>> Is it valid to do compile-time constant folding as an optimization? >> >>IMO, the POLS wouldn't be breeched if this were to happen. > >I can see it going either way--the interpreter could do what it's doing on >purpose, or because the optimization just never was done. (Or that it >wasn't ever really thought about) > >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. I say: 15.002 --> optimise. ;-) Given that we know the base, and it is also constant. This is the thing for me. Constants are, well, constants. If someone redefines "log" to be "ln", then it is no longer constant and you should probably have to recompile everything anyway. Either you meant "15.002" (log) or you meant "34.544" (ln) when you coded this. Or is my understanding faulty? Can you have a constant that is context dependant, post-fact? Regards, -mark.