Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipped tests about number of evaluation of lhs and rhs for flipflop operators in S03-operators/flip-flop.t #3867

Open
p6rt opened this issue May 3, 2015 · 3 comments

Comments

@p6rt
Copy link

p6rt commented May 3, 2015

Migrated from rt.perl.org#124548 (status was 'open')

Searchable as RT124548$

@p6rt
Copy link
Author

p6rt commented Apr 16, 2016

From @usev6

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.)

1 similar comment
@p6rt
Copy link
Author

p6rt commented Apr 16, 2016

From @usev6

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.)

@p6rt
Copy link
Author

p6rt commented Apr 16, 2016

@usev6 - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant