Skip to content

Instantly share code, notes, and snippets.

View nunorc's full-sized avatar

Nuno Ramos Carvalho nunorc

View GitHub Profile
rakudo$ cat constrains.p6
use v6;
my $counter = 0;
multi a(Int $x) {};
multi a($x where {$counter++; True}) {};
a(3);
say $counter;
diff --git a/src/multi-dispatch.pod b/src/multi-dispatch.pod
index 67ce236..eb07595 100644
--- a/src/multi-dispatch.pod
+++ b/src/multi-dispatch.pod
@@ -144,12 +144,22 @@ this to count how often a type check occurs:
=end programlisting
-The first counter output is always C<0>, since the nominal types alone already
-determine which candidate matches best, so the where-block is never executed.
diff --git a/src/core/IO/Socket/INET.pm b/src/core/IO/Socket/INET.pm
index 63d8f4d..9acaf55 100644
--- a/src/core/IO/Socket/INET.pm
+++ b/src/core/IO/Socket/INET.pm
@@ -2,7 +2,7 @@ class IO::Socket::INET is Cool does IO::Socket {
method open (Str $hostname, Int $port) {
- Q:PIR {
+ my $s = Q:PIR {
$ perl rakudo/tools/bench.pl
hello.p6
rakudo-2010.07: 3.873719 seconds
rakudo-master: 3.674719 seconds
rakudo-star: 3.635399 seconds
iteration.p6
rakudo-2010.07: 3.819951 seconds
rakudo-master: 3.841175 seconds
rakudo-star: 3.683934 seconds
recursion.p6
$ cat ABC.pm
grammar ABC::Grammar is HLL::Grammar {
rule TOP { <expr> }
rule expr { <integer> <addop> <integer> };
token addop { '+' | '-' }
token integer { \d+ }
}
class ABC::Actions is HLL::Actions {
Create a list of four times 1:
Main> flip replicate 1 4
[1,1,1,1]
Now do it for every element of the list and get a list of lists:
Main> map (flip replicate 1) [4,1,3,2]
[[1,1,1,1],[1],[1,1,1],[1,1]]
Transpose that twice to get the inner lists sorted by number of elements:
Main> transpose(transpose(map (flip replicate 1) [4,1,3,2]))
$ cat test.p6
multi f([]) { () }
multi f(@list) {
say @list.perl;
}
my @a = ();
f(@a);
use List::Utils;
sub beadsort(@l) {
(transpose(transpose(map {[1 xx $_]}, @l))).map(*.elems);
}
my @list = 2,1,3,5;
say beadsort(@list).perl; # (5, 3, 2, 1)
@nunorc
nunorc / gist:3416716
Created August 21, 2012 15:45
Just for kicks!
$ cat documentation_init.patch
diff --git a/lib/System/Introspector.pm b/lib/System/Introspector.pm
index c46af7d..8316545 100644
--- a/lib/System/Introspector.pm
+++ b/lib/System/Introspector.pm
@@ -5,6 +5,37 @@ package System::Introspector;
our $VERSION = '0.000001';
$VERSION = eval $VERSION;
-# lots of this stuff sponsored by socialflow.com
@nunorc
nunorc / gist:3451005
Created August 24, 2012 14:09
JSON::Diffable fix Makefile.PL typo
diff --git a/Makefile.PL b/Makefile.PL
index 7c5ca12..3a4b73f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -19,7 +19,7 @@ my $mymeta = do { no warnings; $ExtUtils::MakeMaker::VERSION >
WriteMakefile(
NAME => 'JSON-Diffable',
- VERSION_FROM => 'lib/JSON/Diffable.pm'
+ VERSION_FROM => 'lib/JSON/Diffable.pm',