develooper Front page | perl.perl5.porters | Postings from August 2018

Re: [perl #133301] Evalulation order during concat changed

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 11, 2018 15:40
Subject:
Re: [perl #133301] Evalulation order during concat changed
Message ID:
12141_1534002045_5B6F0378_12141_14_1_20180811153718.GK2798@iabyn.com
On Sat, Aug 11, 2018 at 03:36:15PM +0200, Eirik Berg Hanssen wrote:
>   This example demonstrates that the left-hand operand is evaluated _after_
> the right-hand operand, in violation of this "general rule":

There's also an example just with a concat mutator, where the order of
FETCH()es of tied arg changes depending on what the args are. This
ordering is unaffected by the introduction of multiconcat:

    sub TIESCALAR { bless [ $_[1] ]; }
    sub FETCH { my $s = $_[0][0]; print "FETCH($s)\n"; $s }
    sub STORE { print "STORE($_[0][0] => $_[1])\n"; $_[0][0] = $_[1] }

    my ($a,$b,$c);
    tie $a, 'main', 'A';
    tie $b, 'main', 'B';
    tie $c, 'main', 'C';

    $a .= $b;
    #$a .= $b . $c;

with $a .= $b, you get:

    FETCH(A)
    FETCH(B)
    STORE(A => AB)

with $a .= $b . $c you get

    FETCH(B)
    FETCH(C)
    FETCH(A)
    STORE(A => ABC)

Note how it changes from FETCHing the LHS first to the RHS first.

This isn't an example of ordering of operand execution inconsistency,
but of fetching the results of such executions. It none the less
demonstrates the danger of relying on an assumed order.



-- 
"You may not work around any technical limitations in the software"
    -- Windows Vista license

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