Skip to content

Instantly share code, notes, and snippets.

class Set is Iterable does Associative;
has Bool %!elems[Any] handles <keys values elems exists Bool Numeric hash>;
constant term:<∅> = set();
# Immutable
method !STORE(\args) {
die 'Sets are immutable, but you tried to modify one'
}
@TimToady
TimToady / Set.pm
Created January 22, 2012 00:00
Revised for list infixes; added (elem) and (cont) as Texas version
class Set does Associative;
has Bool %!elems;
method keys { %!elems.keys }
method values { %!elems.values }
method elems returns Int { %!elems.elems }
method exists returns Bool { %!elems.exists }
method Bool { %!elems.Bool }
method Numeric { %!elems.Numeric }
@TimToady
TimToady / gist:1828667
Created February 14, 2012 18:07
now mentions native types and warnings on literal OKness smartmatch attemps
OKness type unification (DRAFT)
=======================
Current problems
================
Plethora of acceptance/rejection types/values
Match
True
False
sub logic { first {! try .()}, @_ }
for 1,2,3 X 1,2,3 -> $x, $y {
logic { $x > 2 },
{ $x + $y == 5 },
{ $y < 3 },
{ say "$x + $y == 5"; Nil }
}
sub amb($var,*@a) {
"[{
@a.pick(*).map: {"||\{ $var = $_ }"}
}]";
}
'' ~~ m/
:my ($x, $y);
<{ amb '$x', 1, 2, 3 }>
<?{ $x > 2 }>
sub amb($var,*@a) {
"[{
@a.pick(*).map: {"||\{ $var = '$_' }"}
}]";
}
'' ~~ m/
:my ($a,$b,$c,$d);
<{ amb '$a', <the that a> }>
<{ amb '$b', <frog elephant thing> }>
my $height = 5;
my $width = 5;
my @grid = [ Bool.pick xx $width ] xx $height;
my @neigh = [ ] xx $height;
for ^$height X ^$width -> $i, $j {
@neigh[$i][$j] = gather take @grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < $height and 0 <= $j + .[1] < $width
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
[-1,+1],[+0,+1],[+1,+1];
use Test;
{
my @grid = [ Bool.pick xx 5 ] xx 5;
my @neigh = [ ] xx 5;
for ^5 X ^5 -> $i, $j {
@neigh[$i][$j] = gather take-rw @grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
edo:~/perl6/niecza 1031> gp
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 12 (delta 6), reused 9 (delta 3)
Unpacking objects: 100% (12/12), done.
From github.com:sorear/niecza
6ef6b2c..d41bc4d master -> origin/master
From github.com:sorear/niecza
* [new tag] v17 -> v17
First, rewinding head to replay your work on top of it...
#!/usr/bin/perl
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";
eval { binmode STD, ":utf8" };
use Encode;
for (@ARGV) { Encode::_utf8_on($_) }
$pat = "@ARGV";