On Tue, Jul 6, 2021 at 9:39 AM ToddAndMargo via perl6-users I am confused.

    What I am after it pre-salting $CC.I  with
         $CC.[0] = "abc"
         $CC.[1] = "def"

    with the ".new" functions when I create $CC

    -T

On 7/6/21 12:52 AM, Fernando Santagata wrote:
Hello,

I think that that was exactly what Norman was trying to show. Probably you've been mislead by the first value they assigned in their example:

    my $CC = AA.new( I => [Str,"abc"] );


Here the 'Str' is the "empty" or "undefined" value, since the array was declared as a Str array.

Try this:

 > class AA { has Str @.I is rw }
(AA)
 > my $aa = AA.new: I => ['a','b']
AA.new(I => Array[Str].new("a", "b"))
 > say $aa.I[0]
a
 > say $aa.I[1]
b

or this

 > my $bb = AA.new: I => 'a'
AA.new(I => Array[Str].new("a"))
 > $bb.I[0]
a


Hi Fernando,

Thank you!   Now I understand the syntax better.

$ p6 'class AA { has Str @.I is rw; };
      my $CC = AA.new( I => ["abc","def"] );
      say $CC.I[1];'
def


Follow up question. Since Raku allows me to assign
elements to an array in non sequential order:

    $ p6 'my @x; @x[4]=44; say @x;'
    [(Any) (Any) (Any) (Any) 44]

How to I modify
     my $CC = AA.new( I => ["abc","def"] );
such that I can place values in non sequential order?

For example, I wanted to pre-salt
     $CC.I[4] = "four"
     $CC.I[2] = "two"

Many thanks,
-T




Reply via email to