From: Dan Sugalski Date: 2003-01-07T01:11:05+09:00 Subject: Re: Compile time constant folding? At 12:24 AM +0900 1/7/03, Mark Probert wrote: >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. Maybe, but add isn't necessarily add--it's the actions that need to be taken rather than the values themselves that are in question. If someone redefines + to be unconditional string concatenation, or wedges in logging logic, you may well want that to happen at runtime with the constant expression. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk