-
-
Save peschwa/6bd5b97ab7eda8973667 to your computer and use it in GitHub Desktop.
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
# 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