Skip to content

Instantly share code, notes, and snippets.

View lizmat's full-sized avatar
💭
Functioning within parameters

Elizabeth Mattijsen lizmat

💭
Functioning within parameters
View GitHub Profile
@lizmat
lizmat / gist:5557120
Last active December 17, 2015 05:19
Goal for supporting auth / version / name in module / class / grammar ?
# should produce JRANDOM\nELIZABETH\n as output
module Foo:auth<JRANDOM> {
sub foo is export { say "JRANDOM" };
}
module Foo:auth<ELIZABETH> {
sub foo is export { say "ELIZABETH" };
}
@lizmat
lizmat / gist:7493850
Created November 15, 2013 23:56
some preliminary work on S11
#-------------------------------------------------------------------------------
# LFAV - Support module loading with long name/from/auth/version information
#
# Although the order for specification is usually longname, from, auth and
# version (hence the name of the module LFAV), it was deemed more useful to
# make "from" the top level hash, to easier allow for shortcuts for different
# module sources.
constant Unk := Any;
constant MAGIC_KEY := "LFAV";
@lizmat
lizmat / gist:11404980
Created April 29, 2014 16:15
Duration primitives
sub term:<1sec>() { Duration.new(1) }
sub term:<1second>() { Duration.new(1) }
sub term:<1min>() { Duration.new(60) }
sub term:<1minute>() { Duration.new(60) }
sub term:<1hour>() { Duration.new( 60 * 60 ) }
sub term:<1day>() { Duration.new( 24 * 60 * 60 ) }
sub term:<1week>() { Duration.new( 7 * 24 * 60 * 60 ) }
sub postfix:<secs>($secs) { Duration.new($secs) }
sub postfix:<seconds>($seconds) { Duration.new($seconds) }
@lizmat
lizmat / Proxy huh????
Last active August 29, 2015 14:01
Can someone explain why FETCH is called *EIGHT* times ???
class A is Hash {
method at_key(A:D $hash: $k) {
Proxy.new(
FETCH => {
say "in FETCH with $k";
$hash.exists_key($k) ?? $hash{$k} !! Int;
},
STORE => -> $old, $new {
if $new > 0 {
$hash{$k} = $new;
@lizmat
lizmat / gist:80b8c5b3a02f8a742c0c
Created May 12, 2014 23:34
diff for making BagHash<unknown_key>-- return Int rather than 0
diff --git a/src/core/BagHash.pm b/src/core/BagHash.pm
index 21a35b8..960ea99 100644
--- a/src/core/BagHash.pm
+++ b/src/core/BagHash.pm
@@ -1,39 +1,31 @@
-my class BagHash does Baggy {
+my class BagValue is Int {
+ has $!hash;
+ has $!key;
+
@lizmat
lizmat / gist:48b2c6e3a246eb9f0e25
Last active August 29, 2015 14:01
using signal to have a loop iteration finish
for ^Inf -> $job {
last if state $x;
state $tap = signal(SIGINT).tap( {
say "\b\bwaiting for job #$job to be done";
$x = True;
} );
LAST { $tap.close }
my $working = 5.rand;
say "job #$job for {$working.fmt('%.2f')} seconds";
@lizmat
lizmat / gist:2bbcb4f8799f689da1ff
Created June 16, 2014 13:31
reliable jvm fail for S04-phasers/in-loop.t
$ perl6-j t/spec/S04-phasers/in-loop.rakudo.jvm
1..3
Exception in thread "main" org.perl6.nqp.runtime.UnwindException
at org.perl6.nqp.runtime.ThreadContext.<init>(ThreadContext.java:119)
at org.perl6.nqp.runtime.GlobalContext.getCurrentThreadContext(GlobalContext.java:324)
at org.perl6.nqp.runtime.GlobalContext.<init>(GlobalContext.java:239)
at org.perl6.nqp.runtime.CompilationUnit.enterFromMain(CompilationUnit.java:56)
at perl6.main(gen/jvm/main.nqp)
# t/spec/foo.t
use Test;
plan 1;
#?rakudo todo 'huh?'
throws_like( { die }, X::Comp);
=============================
@lizmat
lizmat / gist:72dc142c2aac6b402b64
Created August 1, 2014 10:50
current rakudo spectest failures on parrot
t/spec/S02-literals/radix.rakudo.parrot (Wstat: 0 Tests: 7 Failed: 0)
Parse errors: Bad plan. You planned 135 tests but ran 7.
t/spec/S02-magicals/DISTRO.rakudo.parrot (Wstat: 0 Tests: 24 Failed: 0)
Parse errors: Bad plan. You planned 28 tests but ran 24.
t/spec/S02-magicals/KERNEL.rakudo.parrot (Wstat: 256 Tests: 32 Failed: 1)
Failed test: 29
Non-zero exit status: 1
t/spec/S02-magicals/VM.rakudo.parrot (Wstat: 0 Tests: 29 Failed: 0)
Parse errors: Bad plan. You planned 32 tests but ran 29.
t/spec/S02-names/is_cached.t (Wstat: 512 Tests: 38 Failed: 2)
@lizmat
lizmat / gist:65d9e44743dffca1157c
Created August 4, 2014 09:42
Exporting dynamic variables delayed until runtime?
# ./Foo.pm
my sub EXPORT(*@a) {
say "in EXPORT";
( '$*FOO' => ++state $ ).hash;
}
============== works as expected
$ perl6 -I. -e 'use Foo; say $*FOO; { use Foo; say $*FOO }; say $*FOO'
in EXPORT