Re: Issue of the week

new topic     » goto parent     » topic index » view thread      » older message » newer message

Carl R. White wrote:
> function old_date()
>     return date()
> end function
>
> without warning
> global function date()
>     sequence D
>     D = old_date()
>     D[D_YEAR] = D[D_YEAR] + 1900
>     return D
> end function
i'm not sure i understand this... or, at the very least,
i wasn't aware that builtin functions could be overloaded...

the only way i can think of to attempt to determine if
i understand this, and it's mechanism, it to throw
an example back, to see if i can apply what i have learned
(or thought i learned) to a problem of practical nature.

a while back, i observed that X*X worked (oftenly)
much faster than power(x,2).
so:
function oldpower(object x, object y)
  return power(x,y)
end function

without warning
function power(object x, object y)
   if int(y) then
        --fast squares
        if y=2 then return x*x   end if
        --fast cubes
        if y=3 then return x*x*x end if
   end if
   return oldpower(x,y)
end function
with warning

now if the above is correct, at least i understand
the implementation of this concept...although,
i'm not so sure i understand the mechanism of
how it works...

('tis one of the reasons i am not partial to C,
 overloading gives me headaches...
   "but! but! but!, that '*' doesn't _really_ mean
    multiplication!")

--Hawke'

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu