Skip to content

Instantly share code, notes, and snippets.

use v6;
our multi sub infix:<transform>($lhs, Callable $rhs) {
$rhs($lhs);
}
our multi sub infix:<transform>($lhs, $rhs) {
$rhs ~~ Whatever ?? $lhs !! $rhs;
}
@uasi
uasi / URI.pm6
Created February 17, 2011 08:07
use v6;
# SYNOPSIS
#
# my $uri = 'http://example.com:8080/path?q#frag';
#
# my %components = URI.parse($uri);
#
# my ($scheme, $auth, $path, $query, $frag) = URI.parse($uri, *);
#
@uasi
uasi / Signature-eqv.p6
Created February 16, 2011 17:45
Cheaty signature equivalence test
use v6;
our multi sub infix:<eqv>(Signature $lhs, Signature $rhs) {
# maybe $lhs.perl.split(';;')[0] eq ...
$lhs.perl eq $rhs.perl &&
?all($lhs.params>>.constraints Zeqv $rhs.params>>.constraints);
}
@uasi
uasi / series-op-tweak.p6
Created February 16, 2011 14:22
Series operator tweak
use v6;
our multi sub infix:<...>(Numeric $rhs, Numeric $lhs where { $rhs <= $lhs }) {
($rhs..$lhs).list;
}
our multi sub infix:<...>(Str $rhs, Str $lhs where { $rhs le $lhs }) {
($rhs..$lhs).list;
}
@uasi
uasi / Hash-hash.patch
Created December 19, 2010 13:15
Implement Hash.hash
diff --git a/src/core/Hash.pm b/src/core/Hash.pm
index b4e135c..41c59e2 100644
--- a/src/core/Hash.pm
+++ b/src/core/Hash.pm
@@ -93,6 +93,10 @@ role Hash is EnumMap {
return self.pairs;
}
+ method hash() {
+ return self;
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm
index 93b73c0..5f0c8b2 100644
--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@@ -860,8 +860,9 @@ rule package_def {
$/.CURSOR.panic('This appears to be Perl 5 code. If you intended it to be Perl 6 code, please use a Perl 6 style package block like "package Foo { ... }", or "module Foo; ...".');
}
}
+ { $*IN_DECL := '' }
<statementlist>
@uasi
uasi / numeric-var-in-decl.patch
Created December 15, 2010 02:49
Possible fix for 'module { "%0" }'
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm
index 93b73c0..6a307ef 100644
--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@@ -797,7 +797,7 @@ token variable {
|| [
| <sigil> <twigil>? <desigilname>
| <special_variable>
- | <sigil> $<index>=[\d+] [ <?{ $*IN_DECL}> <.panic: "Can't declare a numeric variable">]?
+ | <sigil> $<index>=[\d+] [ <?{ $*IN_DECL eq 'variable' }> <.panic: "Can't declare a numeric variable">]?
use v6;
module Foo {
my %escape;
for 0 .. 255 -> $c {
%escape{ chr($c) } = sprintf('%%%02X', $c);
}
our sub bar (Int $value) {
return %escape{ chr($value) };
@uasi
uasi / str-new.patch
Created December 14, 2010 13:22
Makes 'foo'.new return Str()
diff --git a/src/builtins/Str.pir b/src/builtins/Str.pir
index ebee051..4c653cb 100644
--- a/src/builtins/Str.pir
+++ b/src/builtins/Str.pir
@@ -28,6 +28,14 @@ as the Perl 6 C<Str> class.
.tailcall '&infix:<eq>'(topic, self)
.end
+=item new()
+
@uasi
uasi / gist:738122
Created December 12, 2010 15:46
An article for Perl 6 advent calendar 2010
We couldn’t find that file to show.