This ticket is about two currently skipped tests in
S03-operators/flip-flop.t.
The tests in question check how often the left hand side (lhs) and
right hand side (rhs) are evaluated against $_ when using the
operators 'ff' and 'fff', respectively:
# make sure {lhs,rhs} isn't evaluated when state is {true,false}
#?rakudo skip 'dubious scoping? RT #124548'
{
# keep track of # of times lhs and rhs are EVAL'd by adding
# a state var to both sides.
sub ff_eval($code, $lhs, $rhs, @a) {
my $lhs_run = 0;
my $rhs_run = 0;
for @a { $code.({$lhs_run++; ?$lhs}, {$rhs_run++; ?$rhs}); }
return [$lhs_run, $rhs_run];
}
is-deeply ff_eval({@_[0]() ff @_[1]()}, /B/, /B/, <A B A B A>),
[5, 2], "count lhs & rhs evals for ff";
is-deeply ff_eval({@_[0]() fff @_[1]()}, /B/, /B/, <A B A B A>),
[3, 2], "count lhs & rhs evals for fff";
}
Currently, the second test passes, but the first fails because the sub
returns [5, 5]. So lhs and rhs are evaluated 5 times both. After looking
at the speculations (S03), the docs (doc/Language/operators.pod) and
the implementation (sub flipflop src/Perl6/Actions.nqp) I'm under the
impression that [5, 5] is a sensible answer.
* S03 states: "The two sides of a flipflop are evaluated as smartmatches
against the current value of the topic stored in $_.".
That's in line with current behaviour.
* http://doc.perl6.org/routine/ff states: "Compares both arguments to
$_ (that is, $_ ~~ $a and $_ ~~ $b)."
That's also in line with current behaviour.
* src/Perl6/Actions.nqp: There is the following explicit comment in
sub flipflop:
# Evaluate LHS and RHS. Note that in one-only mode, we use
# the state bit to decide which side to evaluate.
All in all, I think the first tests is wrong and should be changed.
(I guess, no adjustments in 6.c-errata are necessary since the test
was skipped there.)