Created
March 14, 2014 23:54
-
-
Save dwarring/9559508 to your computer and use it in GitHub Desktop.
Advent 2013 day 09 - final example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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