Re: Issue of the week

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

> example: this new thread on value()... i can see overloading
> and/or redefining as coming in real handy at this point.

[Code snipped. Mostly reproduced below. See previous post for original]

> would the above be right as a potential pseudocode prototype
> of what [whoever] was asking for???

You've got the concept OK (It's a redefinition). Just a few small quirks:

1) The original subprogram (function/procedure, the one you're redefining
   anyway) must be a built-in or (IIRC) a global subprogram in an included
   library. There's no point in redefining something in the same program
   is there? :)

2) The redefined subprogram must be global (to counter the globality of
   the original)

3) Put it between a "without warning" and "with warning", unless or until
   you bind/shroud the code. (Binding/Shrouding automatically adds a
   "without warning" at the very top of the code, even before the includes
   you might have used.

Re-write time :)

function oldvalue(object x)
    return value(x)
end function

without warning
global function value(object x)
    -- Looking at it, I'm not sure this function would do what you want,
    -- (you'd need a loop or something) but it illustrates the point. :)
    if    find('*',x) then
        -- handle multiply
    elsif find('+',x) then
        -- handle addition
    elsif ... then
        -- subtraction, division, power(^), etc.
    else
        return oldvalue(x) --it's just a normal value() call
    end if -- Don't forget this ;)
end function
with warning

ICYWW[1], the oldvalue() is created to stop unwanted recursion.
If Euphoria couldn't recurse (/me sucks teeth and winces) we wouldn't need
to do this. Actually, if Euphoria couldn't recurse, I don't think I'd be
here. I'd be on a C/Ada mailing list somewhere :)

HTH anyway,
Carl

PS If you've got time, check out SANITY.EX somewhere under the
EUPHORIA/DEMO directory. It uses this technique to redefine abort()...

Footnote:
[1] "In Case You Were Wondering" ;)

--
Carl R White -- Final Year Computer Science at the University of Bradford
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
URL......: http://www.bigfoot.com/~cyrek/
Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr -- B.Q.Vgesa

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

Search



Quick Links

User menu

Not signed in.

Misc Menu