[892] in Coldmud discussion meeting

root meeting help first first in chain previous in chain previous next next in chain last in chain last

Re: [COLD] Operator overloading

daemon@ATHENA.MIT.EDU (Wed Jan 10 16:07:55 1996 )

Date: Wed, 10 Jan 1996 13:46:28 +0000 ()
From: Brandon Gillespie <brandon@tombstone.sunrem.com>
To: coldstuff@tombstone.sunrem.com
In-Reply-To: <199601101300.OAA09048@regoc.srce.hr>
Reply-To: coldstuff@tombstone.sunrem.com

> I don't have the new source on me, but in 2-10, there's 
[snip]
> for addition. So, cthrow could be replaced with the method call on the
> first argument (I don't feel like rummaging through the source to find
> the exact recipe. :) ) Brandon, can this be done?

well, that would be a way to 'override' the plus operator, but what about 
all of the others?

_PERHAPS_ we could do something where when:

     data1 operator data2

would fail, it attempts to do type(data1).op_[add|minus|etc-preknown-word]
(unless data1 is a frob, then call frob.op_...)

and calls that instead.  For instance, this would allow for _simple_ 
overloading, example:

    public method $list.op_add {
        arg d1, d2;

        return d1 + [d2];
    };

So that:

    ;[1, 2, 3] + 1;

Would return as:

    => [1, 2, 3, 4];

However, I'm unsure as to the overall benefits, in general you would be 
creating more work for the driver (since it is not designed for operator
overloading), with the only benefit being more readable (yet abstracted)
code... 

-Brandon