Created
January 13, 2016 12:02
-
-
Save gfldex/2a9a24c64110da844d7e 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
use v6; | |
class Replacement { | |
} | |
use Lib Str; | |
my $g = Guard.new(""); | |
dd $g ~ "abc"; |
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
use v6; | |
role ConcatGuard[::T-right] { | |
has T-right $.attr is rw; | |
method left-type () is nodal { self.WHAT } | |
method right-type () is nodal { T-right } | |
method convert () {...} # --> T-right | |
method new (T-right) {...} | |
# our proto sub infix:<~>(|) {*} | |
# our multi sub infix:<~>(T-left \l, T-right \r) { | |
# l.convert() | |
# } | |
# our multi sub infix:<~>(T-right \l, T-left \r) { | |
# r.new(l); | |
# } | |
} | |
sub EXPORT($T = Str) { | |
class Example is Mu does ConcatGuard[$T] { | |
method convert(){ | |
$.attr.subst('<','<').subst('&', '&'); | |
} | |
method new($s) { | |
self.bless(attr=>$s.subst('&', '&').subst('<', '<')); | |
} | |
} | |
dd $T.WHAT; | |
constant T := $T; | |
dd T.WHAT; | |
{ | |
Guard => Example, | |
'&infix:<~>' => sub (Example \l, T \r){ l ~ r }, | |
'&infix:<~>' => sub (T \l, Example \r){ l ~ r } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment