Re: Version 2.1 -- Persistent parameters ?
- Posted by Quality <quality at ANNEX.COM> Jan 16, 1999
- 526 views
From: Greg Phillips <i.shoot at REDNECKS.COM> > Odd you should mention that, I *just* wrote a function that does that....and >allows the choice between truncation and rounding Pi.... ie: PI(4,0) is >3.1415, while PI(3,1) is 3.142 What can I say... Great minds think alike! > >if anyone's interested, I'll post the source > By all means please do (if it's not huge). ===== Rob: A feature idea (maybe for a future release, unless you can add it easy to 2.1)... I know Euphoria is interpreted but I wonder if it is possible to create "persistent" function parameters (basically I'm thinking "encapsulated" global variables). This discussion on PI might be a good way to explain what I mean... Assume function PI(SIZE,MODE) -- returns some value of the universal constant PI. -- SIZE [an integer] is the number of significant positions to the right of the decimal. (0..MAXPI) -- MODE [a boolean] is a flag for truncate -vs- round the result. (TRUE=ROUND) Persistence means that whatever values were given to SZIE and MODE last are "implied" if not explicitly invoked upon a later call. Thus the following lines of code executed in sequence yield: PI(5,0) -- returns {3.14159} PI(4,1) -- returns {3.1416} PI() -- also returns {3.1416} PI(4,0) -- returns {3.1415} PI() -- also returns {3.1415} When a program starts the values of SIZE and MODE are both set to {-1} by the engine. If the function is invoked in it's "neutral" PI() syntax without **first** being assigned a specific set of parameters it is an error. Ideally there might be some way to offer this feature to the programmer, but it certainly would be a welcome syntax [IMHO] for certain heavily used math functions. What do you think?