Last active
August 29, 2015 14:24
-
-
Save smls/7e1835a2e581cceaaf6a 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
#!/usr/bin/env perl6 | |
class A is Positional { | |
has @!a; | |
method iterator { say " .iterator"; @!a.iterator } | |
method list { say " .list"; @!a.list } | |
method kv { say " .kv"; @!a.kv } | |
method keys { say " .keys"; @!a.keys } | |
method values { say " .values"; @!a.values } | |
method elems { say " .elems"; @!a.elems } | |
method end { say " .end"; @!a.end } | |
method AT-POS (::?CLASS:D: $index) is rw { | |
say " .AT-POS: {$index.perl}"; | |
@!a[$index] | |
} | |
method EXISTS-POS (::?CLASS:D: $index) { | |
say " .EXISTS-POS: {$index.perl}"; | |
@!a[$index]:exists | |
} | |
method DELETE-POS (::?CLASS:D: $index) { | |
say " .DELETE-POS: {$index.perl}"; | |
@!a[$index]:delete | |
} | |
method ASSIGN-POS (::?CLASS:D: $index, $value) { | |
say " .ASSIGN-POS: {$index.perl}, {$value.perl}"; | |
@!a[$index] = $value | |
} | |
method BIND-POS (::?CLASS:D: $index, \value) { | |
say " .BIND-POS: {$index.perl}, {value.perl}"; | |
@!a[$index] := value | |
} | |
method perl { @!a.list.perl } | |
} | |
# Testing: | |
my @a := A.new; | |
say '@a[0, 1] = 5, 10'; | |
@a[0, 1] = 5, 10; | |
say '@a[0..10]'; | |
@a[0..10]; |
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
@a[0, 1] = 5, 10 | |
.AT-POS: 0 | |
.AT-POS: 1 | |
@a[0..10] | |
.list | |
.AT-POS: 0 | |
.AT-POS: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment