Skip to content

Instantly share code, notes, and snippets.

View nncal.raku
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;
View foo.txt
ub exclude(@a, $elems) {
say (0..^$elems).grep: * !~~ @a
}
my @a = 1..10;
@a[&exclude.assuming(2..3)].say;
View Restricted.rakumod
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.
View coerce-subsets.raku
use v6.*;
class Type is Int { }
subset Even of Type where * %% 2;
Type.^add_method('COERCE', my method COERCE(|) {
my Even $retval = 42
});
sub foo(Even() $_) { .&dd }
foo answer;
View spinner.raku
use v6.d;
# my @loop = |("\x1F550" .. "\x1F55B") xx *;
# react whenever Supply.interval(0.1) {
# state $it = @loop.iterator;
# print "\b\b" ~ $it.pull-one;
# }
sub progress-bar($max, $width = 10) {
View did-you-know.raku
# Did you know, you can use the method `.none` (and friends) of `Any` in a method call chain?
my \fib = 1, 1, * + * … ∞;
say so fib[^10].none.is-prime;
say so fib[^10].any.is-prime;
say so fib[5..9].one.is-prime;
# A `Junction` is a parallel value that whats to collaps into a single `Bool`. Any method call to a definite `Junction` will be forwarded to its members, coerced to `Bool` and collapsed with the `Junction`-type. The above `any`-form is equivalent to:
View poetry.raku
# Did you know you can translate to following Perl poem to Raku?
# perl -e 'do not $fear and do not die'
try { not :2(.fear) } and do not die
View in-response.txt
Hi Hillel,
you where asking for a very strange programming in "Six Programming
Languages I'd Like to See". We already made that for you. It is called
Raku (was called Perl 6) and can be found at www.raku.org.
The following is valid Raku code:
try {
class :: { # I didn't came up with a good name, so I didn't gave one to this class.
View parameterised-attribute.raku
use v6.d;
role BitMask[@names] {
has uint64 $.mask;
sub names-to-bits(@a) {
my int $mask;
for @a -> $s {
$mask = $mask +| (1 +< @names.first($s, :k) // fail('bad‼'))
}
View Log.rakumod
use v6.d;
my role Functor {
has $.message;
my $.level;
has $.captured-loglevel;
has $.file;
has $.line;
method CALL-ME(*@message) {
my ($line, $file) = callframe(1).&{ .line, .file };