Created
November 1, 2015 19:44
-
-
Save lizmat/0492103c6680fe6d2ec3 to your computer and use it in GitHub Desktop.
Must not be understanding MMD after all
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
Given these Supply methods in the core setting, | |
$ ack ' method Supply' src/core | |
src/core/Any.pm | |
66: proto method Supply(|) is nodal { * } | |
src/core/List.pm | |
672: multi method Supply(List:D:) { Supply.from-list(self) } | |
src/core/Promise.pm | |
204: multi method Supply(Promise:D:) { | |
src/core/Supply.pm | |
88: multi method Supply(Supply:) { self } | |
89: multi method Supply(Any:D:) { | |
102: multi method Supply(IO::Handle:D: :$size = 65536, :$bin --> Supply:D) { | |
one would expect this to work. But it doesn't: | |
$ 6l '42.Supply.tap: &say' | |
Use of uninitialized value of type Any in string context | |
Any of .^name, .perl, .gist, or .say can stringify undefined things, if needed. in block <unit> at -e:1 | |
Cannot call Supply(Int); none of these signatures match: | |
at gen/moar/m-CORE.setting:18589 (/Users/liz/Github/rakudo.moar/install/share/perl6/runtime/./CORE.setting.moarvm:throw:186) | |
from gen/moar/m-CORE.setting:20646 (/Users/liz/Github/rakudo.moar/install/share/perl6/runtime/./CORE.setting.moarvm::48) | |
from gen/moar/m-BOOTSTRAP.nqp:2330 (blib/Perl6/BOOTSTRAP.moarvm::718) | |
from gen/moar/m-CORE.setting:1738 (/Users/liz/Github/rakudo.moar/install/share/perl6/runtime/./CORE.setting.moarvm:Supply:41) | |
from -e:1 (<ephemeral file>:<unit>:24) | |
from -e:1 (<ephemeral file>:<unit-outer>:10) |
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
diff --git a/src/core/Any.pm b/src/core/Any.pm | |
index 83570bd..ac28651 100644 | |
--- a/src/core/Any.pm | |
+++ b/src/core/Any.pm | |
@@ -63,6 +63,7 @@ my class Any { # declared in BOOTSTRAP | |
multi method Slip() { self.list.Slip } | |
proto method Array(|) is nodal { * } | |
multi method Array() { self.list.Array } | |
+ proto method Supply(|) is nodal { * } | |
proto method hash(|) is nodal { * } | |
multi method hash(Any:U:) { my % = () } | |
@@ -398,7 +399,6 @@ my class Any { # declared in BOOTSTRAP | |
method BagHash() is nodal { BagHash.new-from-pairs(self.list) } | |
method Mix() is nodal { Mix.new-from-pairs(self.list) } | |
method MixHash() is nodal { MixHash.new-from-pairs(self.list) } | |
- method Supply() is nodal { self.list.Supply } | |
method nl() { "\n" } | |
method print-nl() { self.print(self.nl) } | |
diff --git a/src/core/IO/Handle.pm b/src/core/IO/Handle.pm | |
index ad8d0cd..b4f7081 100644 | |
--- a/src/core/IO/Handle.pm | |
+++ b/src/core/IO/Handle.pm | |
@@ -779,30 +779,6 @@ my class IO::Handle does IO { | |
#?endif | |
} | |
- method Supply(IO::Handle:D: :$size = 65536, :$bin --> Supply:D) { | |
- if $bin { | |
- supply { | |
- my $buf := self.read($size); | |
- while nqp::elems($buf) { | |
- emit $buf; | |
- $buf := self.read($size); | |
- } | |
- done; | |
- } | |
- } | |
- else { | |
- supply { | |
- my int $chars = $size; | |
- my str $str = self.readchars($chars); | |
- while nqp::chars($str) { | |
- emit nqp::p6box_s($str); | |
- $str = self.readchars($chars); | |
- } | |
- done; | |
- } | |
- } | |
- } | |
- | |
# second arguemnt should probably be an enum | |
# valid values for $whence: | |
# 0 -- seek from beginning of file | |
diff --git a/src/core/List.pm b/src/core/List.pm | |
index de97cd7..d8326cb 100644 | |
--- a/src/core/List.pm | |
+++ b/src/core/List.pm | |
@@ -669,7 +669,7 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP | |
} | |
method FLATTENABLE_HASH() { nqp::hash() } | |
- method Supply(List:D:) { Supply.from-list(self) } | |
+ multi method Supply(List:D:) { Supply.from-list(self) } | |
method CALL-ME(List:U: |c) { | |
self.new(|c); | |
diff --git a/src/core/Promise.pm b/src/core/Promise.pm | |
index cbecd38..d60c4b6 100644 | |
--- a/src/core/Promise.pm | |
+++ b/src/core/Promise.pm | |
@@ -201,7 +201,7 @@ my class Promise { | |
$p | |
} | |
- method Supply(Promise:D:) { | |
+ multi method Supply(Promise:D:) { | |
my $s = Supply.new; | |
self.then({ | |
if self.status == Kept { | |
diff --git a/src/core/Supply.pm b/src/core/Supply.pm | |
index 60159ff..c8a14b2 100644 | |
--- a/src/core/Supply.pm | |
+++ b/src/core/Supply.pm | |
@@ -85,7 +85,44 @@ my role Supply { | |
method taps(Supply:D:) { +@!tappers } | |
method live(Supply:D:) { True }; | |
- method Supply(Supply:) { self } | |
+ multi method Supply(Supply:) { self } | |
+ multi method Supply(Any:D:) { | |
+ if nqp::istype(self,Iterable) { | |
+ my $iter = self.iterator; | |
+ supply { | |
+ my $pulled; | |
+ emit $pulled until ($pulled := $iter.pull-one) =:= IterationEnd; | |
+ done; | |
+ } | |
+ } | |
+ else { | |
+ supply { emit self; done } | |
+ } | |
+ } | |
+ multi method Supply(IO::Handle:D: :$size = 65536, :$bin --> Supply:D) { | |
+ if $bin { | |
+ supply { | |
+ my $buf := self.read($size); | |
+ while nqp::elems($buf) { | |
+ emit $buf; | |
+ $buf := self.read($size); | |
+ } | |
+ done; | |
+ } | |
+ } | |
+ else { | |
+ supply { | |
+ my int $chars = $size; | |
+ my str $str = self.readchars($chars); | |
+ while nqp::chars($str) { | |
+ emit nqp::p6box_s($str); | |
+ $str = self.readchars($chars); | |
+ } | |
+ done; | |
+ } | |
+ } | |
+ } | |
+ | |
method Channel(Supply:D:) { | |
my $c = Channel.new(); | |
self.tap( -> \val { $c.send(val) }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment