develooper Front page | perl.perl6.language.objects | Postings from November 2001

Re: Stupid Newbie Question

Thread Previous | Thread Next
From:
Piers Cawley
Date:
November 9, 2001 01:45
Subject:
Re: Stupid Newbie Question
Message ID:
m2eln830e8.fsf@bofh.org.uk
Dan Sugalski <dan@sidhe.org> writes:

> At 04:21 PM 11/8/2001 -0800, John Rudd wrote:
>>So, does this mean my other heart's desire of operator overloading might
>>be coming forth?  (I know, I know, here I am, a smalltalker, asking for
>>operator overloading ... but, what are the smalltalkers gonna do, take
>>away my membership card?)
> 
> What, you mean being able to override the + function for a variable,
> complete with method dispatch depending on the types of the variables
> on both sides of the +?
> 
> Yup.... ;)

Um, you do realise you don't need multi dispatch to do operator
overloading don't you?

    package Foo;

    use overload 
        '+' => my_add,
        ...
        ;
   
    sub my_add {
        my $self = shift;
        my $target = shift;

        $target->add_Foo($self);
    }

    ...

And we can do that today. 'cept it's something of a PITA because
'real' numbers don't respond to object methods.

Every so often I find myself thinking 'I should implement something
that automagically turns all numbers and strings into objects', but
there's always something more important to do.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About