Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lizmat-nano
- Loading branch information
Showing
13 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use MONKEY; | ||
augment class Int { | ||
proto method roll(|) {*} | ||
multi method roll() { nqp::rand_I(self,Int) } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
augment class Rakudo::Iterator { | ||
# Return an iterator that generates Lists of a given iterator | ||
# and one or Callables with conditions. This is basically the | ||
# Haskell "span" functionality. | ||
my class Snip does Iterator { | ||
has $!tests; | ||
has $!iterator; | ||
has $!next; | ||
|
||
method !SET-SELF(@tests, $iterator) { | ||
$!tests := nqp::getattr(@tests,List,'$!reified'); | ||
$!iterator := $iterator; | ||
$!next := $iterator.pull-one; | ||
self | ||
} | ||
|
||
method new(@tests, $iterator) { | ||
nqp::create(self)!SET-SELF(@tests, $iterator) | ||
} | ||
|
||
method pull-one() { | ||
if nqp::eqaddr($!next,IterationEnd) { | ||
IterationEnd | ||
} | ||
else { | ||
my $buffer := nqp::create(IterationBuffer); | ||
nqp::push($buffer,$!next); | ||
|
||
my $iterator := $!iterator; | ||
my $pulled; | ||
|
||
if nqp::elems($!tests) { | ||
my $test := nqp::shift($!tests); | ||
nqp::until( | ||
nqp::eqaddr(($pulled := $iterator.pull-one),IterationEnd) | ||
|| nqp::isfalse($test.ACCEPTS($pulled)), | ||
nqp::push($buffer,$pulled) | ||
); | ||
|
||
} | ||
else { | ||
nqp::until( | ||
nqp::eqaddr(($pulled := $iterator.pull-one),IterationEnd), | ||
nqp::push($buffer,$pulled) | ||
); | ||
} | ||
|
||
$!next := $pulled; | ||
$buffer.List | ||
} | ||
} | ||
} | ||
|
||
proto method Snip(|) {*} | ||
multi method Snip(\test, $iterator) { Snip.new: (test,), $iterator } | ||
multi method Snip(@tests, $iterator) { Snip.new: @tests, $iterator } | ||
} | ||
|
||
# vim: expandtab shiftwidth=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
augment class Supply { | ||
proto method snip($, |) {*} | ||
multi method snip(Supply:D: $test) { | ||
self.snip( ($test,) ) | ||
} | ||
|
||
multi method snip(Supply:D: @tests) { | ||
my @left = @tests; | ||
my $test := @left ?? @left.shift !! Nil; | ||
my $buffer := nqp::create(IterationBuffer); | ||
supply { | ||
whenever self -> \val { | ||
if nqp::eqaddr($test,Nil) { | ||
nqp::push($buffer,val); | ||
} | ||
elsif $test.ACCEPTS(val) { | ||
emit $buffer.List; | ||
nqp::push(($buffer := nqp::create(IterationBuffer)),val); | ||
$test := @left ?? @left.shift !! Nil; | ||
} | ||
else { | ||
nqp::push($buffer,val); | ||
} | ||
LAST { | ||
emit $buffer.List; | ||
} | ||
} | ||
} | ||
} | ||
|
||
multi method snip(Supply:D: *@tests) { | ||
self.snip(@tests) | ||
} | ||
} | ||
|
||
# vim: expandtab shiftwidth=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,6 +433,7 @@ my @expected = ( | |
Q{&sleep-until}, | ||
Q{&slip}, | ||
Q{&slurp}, | ||
Q{&snip}, | ||
Q{&so}, | ||
Q{&sort}, | ||
Q{&splice}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,6 +430,7 @@ my %allowed = ( | |
Q{&sleep-until}, | ||
Q{&slip}, | ||
Q{&slurp}, | ||
Q{&snip}, | ||
Q{&so}, | ||
Q{&sort}, | ||
Q{&splice}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
src/core.e/core_prologue.pm6 | ||
src/core.e/control.pm6 | ||
src/core.e/Any-iterable-methods.pm6 | ||
src/core.e/Supply.pm6 | ||
src/core.e/PseudoStash.pm6 | ||
src/core.e/Grammar.pm6 | ||
src/core.e/EXPORTHOW.pm6 | ||
src/core.e/Int.pm6 | ||
src/core.e/array_multislice.pm6 | ||
src/core.e/hash_multislice.pm6 | ||
src/core.e/Rakudo/Internals/Sprintf.pm6 | ||
src/core.e/Any-iterable-methods.pm6 | ||
src/core.e/Rakudo/Iterator.pm6 |