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

Re: How to define a new value type?

Thread Previous | Thread Next
From:
TSa
Date:
September 15, 2008 01:06
Subject:
Re: How to define a new value type?
Message ID:
48CE1771.2050909@vts-systems.de
HaloO,

John M. Dlugosz wrote:
> Since infix:<=> is an operator called on the value of the 
> left-hand-side, the semantics are naturally value semantics, as in C++.  
> It would be difficult to write it otherwise: take the LHS by ref and 
> call STORE on the container.

Taking only the lhs into account doesn't work in Patrick's
code because he has untyped variables. The Dog is only on
the rhs. This is why I think we need a binary dispatch. I
don't see much use for the type of the LHS, though. C++
dispatches assignment on the declared type of the container
on the LHS. This hardly makes sense in Perl 6.

If we had a role Value then we could have a

    multi sub infix:<=> (Any $lhs, Value $rhs --> Value)
    {
        return $rhs.clone;
    }

that is called after the FETCH of the rhs and before the STORE of
the lhs by the low-level handling of assignment. One use of more
specific dispatch targets e.g. infix:<=>:(Dog, Dog --> Dog) could
be an optimized internal handling of shallow assignment.

Regards, TSa.
-- 

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
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