Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 14:24
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 smls/7e1835a2e581cceaaf6a to your computer and use it in GitHub Desktop.
Save smls/7e1835a2e581cceaaf6a to your computer and use it in GitHub Desktop.
#!/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];
@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