Skip to content

Instantly share code, notes, and snippets.

@dwarring
Created March 14, 2014 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwarring/9559508 to your computer and use it in GitHub Desktop.
Save dwarring/9559508 to your computer and use it in GitHub Desktop.
Advent 2013 day 09 - final example
my $lisp-list = 1 => 2 => 3 => Nil; # it's nice that infix:<< => >> is right-associative
Pair.^add_fallback(
-> $, $name { $name ~~ /^c<[ad]>+r$/ }, # should we handle this? yes, if /^c<[ad]>+r$/
-> $, $name { # if it turned out to be our job, this is what we do
-> $p {
$name ~~ /^c(<[ad]>*)(<[ad]>)r$/; # split out last 'a' or 'd'
my $r = $1 eq 'a' ?? $p.key !! $p.value; # choose key or value
$0 ?? $r."c{$0}r"() !! $r; # maybe recurse
}
}
);
is $lisp-list.caddr, 3, 'Pair.^add_fallback';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment