@ToddandMargo wrote:
Now I understand. You are using Str as a
> skip, skip, drop 2, skip, drop 4
> This is a sequential workaround.
> Also I was confused as I though Str was only
> a type declaration and could be used this way.
> What I would like to see is direct access, without the
> skips.
> In other words, the pre-salt equivalent of
> class AA { has Str @.I is rw };
> my $CC = AA.new;
> $CC.I[400] = "four hundred"
> $CC.I[2000] = "two thousand"
> writing out 2000 skips is not practical.
I definitely agree with you, so let's use what we know of Raku to our
advantage. A hash structure would work well, here with the
Array-Indexes-to-Use as keys:
class AA {
has @.I;
submethod BUILD (:$data) {
@!I[.key] = .value for $data[]
}
method new (*@data) {
self.bless( data => @data )
}
}
You can now do the following:
AA.new(2 => 'b', 4 => 66, 9 => 'apples')
Which makes for a nice initializer!
- X