Skip to content

Instantly share code, notes, and snippets.

@perlpilot
Created December 7, 2011 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlpilot/1443400 to your computer and use it in GitHub Desktop.
Save perlpilot/1443400 to your computer and use it in GitHub Desktop.
flip-flop factorization
my sub FF($pos, Bool $a, Bool $b,
:$x-left as Bool = False, :$x-right as Bool = False, :$sed-like as Bool = False) {
state %ffv;
my sub flop-check {
if $b {
%ffv{$pos} = False;
$:x-right ?? False !! True;
} else {
True;
}
}
if %ffv{$pos} {
flop-check;
}
elsif $a {
%ffv{$pos} = $a;
if $:x-left { False }
flop-check unless $:sed-like;
}
else {
False
}
}
sub infix:<ff>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b);
}
sub infix:<ff^>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :x-right);
}
sub infix:<^ff>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :x-left);
}
sub infix:<^ff^>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :x-left, :x-right);
}
sub infix:<fff>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :sed-like);
}
sub infix:<fff^>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :sed-like, :x-right);
}
sub infix:<^fff>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :sed-like, :x-left);
}
sub infix:<^fff^>($a as Bool, $b as Bool) {
my $pos := nqp::p6box_s(nqp::callerid());
FF($pos, $a,$b, :sed-like, :x-left, :x-right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment