Skip to content

Instantly share code, notes, and snippets.

@peschwa
Last active August 29, 2015 14:04
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 peschwa/6bd5b97ab7eda8973667 to your computer and use it in GitHub Desktop.
Save peschwa/6bd5b97ab7eda8973667 to your computer and use it in GitHub Desktop.
# subroutine solution:
my $*GOAL;
sub g($in = 'o') {
$*GOAL = $*GOAL ?? $*GOAL ~ $in !! 'g' ~ $in;
if $in eq 'al' {
$*GOAL ~= "\n";
return $*GOAL = $*GOAL but False
}
&?ROUTINE # return the current subroutine
}
print g('al');
print g()('al');
print g()()()()('al');
# role solution (if "i need the sigil" doesn't disqualify it):
role o-role {
multi method postcircumfix:<( )>($o) {
return (self ~ 'o') does o-role;
}
multi method postcircumfix:<( )>($o where $o eq 'al') {
return (self ~ "al\n");
}
}
role g-role {
method postcircumfix:<( )>($g = '') {
return ('g' does o-role)($g);
}
}
my $g = 'g' does g-role;
print $g('al');
print $g()()()('al');
# ^- this sigil can't go away :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment