On Mon, 12 Mar 2007, Sebastian Hungerecker wrote:

> ara.t.howard / 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:
>

> Imagine you would call the function with rand() as parameter. With #define
> rand would be called three times, with def it would be called once and its
> value would be used three times.

absolutely.  but that's generally considered a problem with macros, not a
feature.  besides, that's easy too

   harp:~ > cat a.rb
   def myfunc *a, &b
     x = a.shift || b.call
     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)

   # x as rand
   p myfunc{ rand }


regards.


-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama