From: Mike Date: 2007-03-12T18:00:25+09:00 Subject: Re: #define alternative for Ruby On Mar 12, 4:21 pm, ara.t.how...@noaa.gov wrote: > On Mon, 12 Mar 2007, Mike wrote: > > > I was talking more about macros rather then constants. But I agree that > > constant are convenient way to substitute "#define myconst 15". But can you > > substitute "#define myfunc(x) (sin(x)*cos(x)*exp(x))"? You should know that > > "x" could be as much other functions as a constant/variable. > > perhaps i'm being dense, but i fail to see how the above example is none other > than a simple function in ruby: > > harp:~ > cat a.rb > def myfunc x > Math.sin(x) * Math.cos(x) * Math.exp(x) > end > > # x as function > def x() 42 end > p myfunc(x) > > # x as constant > X = 42 > p myfunc(X) > > # x as variable > x = 42 > p myfunc(x) > > harp:~ > ruby a.rb > 6.37609775534436e+17 > 6.37609775534436e+17 > 6.37609775534436e+17 > > text macros like the above are really only useful in static/strong typed > languages. in ruby, they are rather meaningless. > > regards. > > -a > -- > be kind whenever possible... it is always possible. > - the dalai lama Just try to implement: set_default(var, val) -- if variable "var" is not defined (not existed) then assign value "val"