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

Re: [svn:perl6-synopsis] r14585 - doc/trunk/design/syn

Thread Previous | Thread Next
From:
TSa
Date:
October 5, 2008 05:45
Subject:
Re: [svn:perl6-synopsis] r14585 - doc/trunk/design/syn
On Wednesday, 1. October 2008 21:54:12 larry@cvs.perl.org wrote:
>  If you apply an assignment operator to a protoobject, it is assumed that
>  you are implementing some kind of notional "reduction" to an accumulator
> -variable.  To that end, the base operator is dropped and a simple
> -assignment is done instead.  Hence you may correctly write:
> +variable.  To that end, the operation is defined in terms
> +of the corresponding reduction operator, where the protoobject
> +becomes the operator's identify value.  So if you say:
> +
> +    $x -= 1;
> +
> +it is more or less equivalent to:
> +
> +    $x = [-]() unless defined $x;	# 0 for [-]()
> +    $x = $x - 1;
> +
> +and $x ends up with -1 in it, as expected.

Can't we have that as a general feature of all operators?
That is:

   my ($x, $y);

   say $x * $y; # prints 1
   say $x + $y; # prints 0

It is a cleaver idea to make the operator choose an appropriate
value for a Nothing value. Why having that only for meta operators?


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


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About