Skip to content

Instantly share code, notes, and snippets.

sub foo($a) {
multi sub when(Int:D $a) { say $a.WHAT; }
multi sub when(Str:D $s) { say $s.WHAT; }
multi sub when(|) { say ‘default’ }
when($a);
}
foo ('Answer', 42, Nil).all;
You are there:
No such method 'add-colonpair' for invocant of type
'RakuAST::ColonPair::Value'
at SETTING::src/core.c/Exception.pm6:64 (/usr/local/src/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:throw)
from src/Perl6/Metamodel/Configuration.nqp:60 (/usr/local/src/rakudo/install/share/perl6/lib/Perl6/Metamodel.moarvm:throw_or_die)
from src/vm/moar/dispatchers.nqp:676 (/usr/local/src/rakudo/install/share/perl6/lib/Perl6/BOOTSTRAP/v6c.moarvm:report-method-not-found)
from src/vm/moar/dispatchers.nqp:613 (/usr/local/src/rakudo/install/share/perl6/lib/Perl6/BOOTSTRAP/v6c.moarvm:)
from src/Raku/Actions.nqp:782 (/usr/local/src/rakudo/install/share/perl6/lib/Raku/Actions.moarvm:EXPR)
from NQP::src/HLL/Grammar.nqp:554 (/usr/local/src/rakudo/install/share/nqp/lib/NQPHLL.moarvm:EXPR_reduce)
from NQP::src/HLL/Grammar.nqp:514 (/usr/local/src/rakudo/install/share/nqp/lib/NQPHLL.moarvm:EXPR)
from <unknown>:1 (/usr/local/src/rakudo/install/share/perl6/lib/Raku/Grammar.moarvm:arglist)
use v6.*;
# my $a = '1 B';
#
# if $a ~~ /(<digit>) \s (<alpha>)/ -> $_ {
# my ($one, $B) = .deepmap: *.Str;
# say "$one $B";
# }
#
# if $a ~~ /(<digit>) \s (<alpha>)/ -> Match (Str() $one, Str() $B) {
use uniname-words;
constant $stdin-text = qq:to/EOH/;
I ♥ Raku!
1 22 333 4444 55555 6565656
3.14159265358979323846264338327950288419716939937510582097494459
A line with the number 42.
We may need some "quotes".
A backslash \\
would be nice too.
use uniname-words;
constant $stdin-text = qq:to/EOH/;
I ♥ Raku!
1 22 333 4444 55555 6565656
3.14159265358979323846264338327950288419716939937510582097494459
A line with the number 42.
We may need some "quotes".
A backslash \\
would be nice too.
sub limit-rate(Supply $in, $per-seconds = 1 --> Supply:D) {
my $out = Supplier::Preserving.new;
start react whenever $in -> \value {
$out.emit: value;
sleep(1 / $per-seconds);
}
$out.Supply;
}
use v6.d;
constant @keymap = (0x1b, 0x5b, 0x31, 0x31, 0x7e) => 'F1', (0x61,) => 'a', (0x0a,) => 'ENTER';
use Term::ReadKey;
react {
whenever key-pressed( :!echo ) {
state @stack;
@stack.push: .ord;
# .ord.fmt('%02x').put; # uncomment to discover new keycodes
multi sub MAIN(Bool :$S, Bool :$three) {
constant @months = <January February March April May June July August September October November December>;
my @week-days = $S ?? <Su Mo Tu We Th Fr Sa> !! <Mo Tu We Th Fr Sa Su>;
my &start-week-day = $S ?? { .[0].day-of-week % 7 } !! { .[0].day-of-week - 1 }
my $month-offset = $three ?? -1 !! 0;
loop {
$_ = now.Date.truncated-to('month');
$_ = .earlier(:month(1)) if $three;
@gfldex
gfldex / foo.txt
Created September 29, 2022 22:54
ub exclude(@a, $elems) {
say (0..^$elems).grep: * !~~ @a
}
my @a = 1..10;
@a[&exclude.assuming(2..3)].say;