develooper Front page | perl.perl6.language | Postings from April 2008

Re: Polymorphism and Representations (Was: Re: First look: AdvancedPolymorphism whitepaper)

Thread Previous | Thread Next
From:
TSa
Date:
April 30, 2008 07:36
Subject:
Re: Polymorphism and Representations (Was: Re: First look: AdvancedPolymorphism whitepaper)
Message ID:
481883DC.4080202@barco.com
HaloO,

John M. Dlugosz wrote:
> TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:
>>
>>    multi infix:<=> (Any $lhs, A $rhs)
>>    {
>>        $lhs.STORE($rhs.clone); # or .cow if that's not automatic
>>    }
>>
>>
>   $lhs.VAR.STORE.

I guess I also forgot the is rw to get a binding to the caller's
container not the local one of the sub. Otherwise you could write
into the caller's container without rw in the sig.

The issue I want to address is how easy it is to implement
immutable semantics. The ref copying is sort of an annoyance
there.

    class A
    {
        has $.a = 0;
        submethod BUILD ($.a) {}
        method inc ($self is rw:) # get at the container of
        {                         # of the caller
            $self = self.^new(self.a + 1);
            # return self.^new(self.a + 1) without the rw
            # sadly doesn't work for $x.inc syntax
        }
    }

    my A $a .= new(7);
    my A $b = $a;

    $a === $b; # true
    $a eqv $b; # true

    $a.inc; # shall behave like ++ for Int

    $a === $b; # false
    $a eqv $b; # false

The spec also says that one has to use .=method to call an in-place
mutator. That is $x.inc in Daniel's example should actually mean
$x = $x.inc along the lines that $x++ also means $x = $x + 1.

Finally combine that with the wish to allow literals of class A. Let's
assume the grammar is patched to parse integer literals as As. Then
with the above 7.inc gives an error because 7 is not mutable. So as
I outlined before I want to care for the callers constraint. Perl 6
lacks a syntax for that.


> My readings have been that = just copies the ref.  Unless it's a "value 
> type" or "immutable" which just means that it doesn't matter.  I'll have 
> to read up on that some more soon.

Keep us informed, please.


Regards, TSa.
-- 

"The unavoidable price of reliability is simplicity"  -- C.A.R. Hoare
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

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