Created
March 12, 2015 21:02
-
-
Save ab5tract/00a98457cd5c0989efd4 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
class Codeword { | |
has Supply $.printer; | |
# has Sub $!codeword; | |
has Sub $.scrambler is rw; | |
has $!string; | |
has $!encoded-string; | |
method new( :$string = "bloop" ) { | |
my $printer = Supply.new; | |
$printer.act: { $_.say }; | |
self.bless( :$string, :$printer ); | |
} | |
submethod BUILD( :$!string, :$!printer ) { | |
# my sub codeword is rw { | |
# return Proxy.new: | |
# FETCH => method () { $!encoded-string }, | |
# STORE => method ($s) { $!encoded-string = scrambler($s) }; | |
# } | |
# $!codeword = &codeword; | |
my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii } | |
$!scrambler := &scrambler; | |
} | |
sub codeword is rw { | |
return Proxy.new: | |
FETCH => method () { $!encoded-string }, | |
STORE => method ($s) { $!encoded-string = $!scrambler($s) }; | |
} | |
method encode( Str $string ) { | |
codeword() = $string; | |
} | |
method display { | |
$!printer.emit( $!encoded-string ||= $!scrambler($!string) ); | |
# say $!encoded-string ||= scrambler($s); | |
if codeword() { | |
codeword(); | |
} else { | |
codeword() = $!string; | |
codeword(); | |
} | |
} | |
} | |
my $code = Codeword.new; | |
$code.display; |
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
+ proxy-test.p6 (22 - 26) | |
| # $!codeword = &codeword; | |
| | |
| my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii } | |
| $!scrambler := &scrambler; | |
| } | |
> | |
+ proxy-test.p6 (9 - 13) | |
| method new( :$string = "bloop" ) { | |
| my $printer = Supply.new; | |
| $printer.act: { $_.say }; | |
| | |
| self.bless( :$string, :$printer ); | |
> | |
oybbc | |
+ proxy-test.p6 (39 - 43) | |
| $!printer.emit( $!encoded-string ||= $!scrambler($!string) ); | |
| # say $!encoded-string ||= scrambler($s); | |
| if codeword() { | |
| codeword(); | |
| } else { | |
> | |
+ proxy-test.p6 (27 - 33) | |
| | |
| sub codeword is rw { | |
| return Proxy.new: | |
| FETCH => method () { $!encoded-string }, | |
| STORE => method ($s) { $!encoded-string = $!scrambler($... | |
| } | |
| | |
> | |
+ proxy-test.p6 (28 - 32) | |
| sub codeword is rw { | |
| return Proxy.new: | |
| FETCH => method () { $!encoded-string }, | |
| STORE => method ($s) { $!encoded-string = $!scrambler($... | |
| } | |
> | |
~/.rakudobrew/bin/perl6-debug-m: line 2: 6394 Segmentation fault: 11 /Users/jhaltiwanger/.rakudobrew/bin/../moar-HEAD/install/bin/perl6-debug-m "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment