On Tue, 6 Jul 2021 at 10:55, ToddAndMargo via perl6-users <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:

    Hi All,

    On creation, I would like to salt some of the
    values inside an object  when the variable
    inside is an array:


    First a concept test:
    $ p6 'class AA { has Str @.I is rw; }; my $CC= AA.new; $CC.I[1] =
    "def";
    say $CC.I[1];'

    def


    Now for the pre-salt test
    $ p6 'class AA { has Str @.I is rw; }; my $CC = AA.new( I[1] =>
    "abc" );
    say $CC.I[1];'

    ===SORRY!=== Error while compiling -e
    Undeclared name:
          I used at line 1


    What am I doing wrong?

    Many thanks,
    -T

On 7/5/21 10:45 PM, Norman Gaywood wrote:
$ raku
Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.06.
Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
Built on MoarVM version 2021.06.

To exit type 'exit' or '^D'
 > class AA { has Str @.I is rw; };
(AA)
 > my $CC = AA.new( I => [Str,"abc"] );
AA.new(I => Array[Str].new(Str, "abc"))
 > say $CC.I;
[(Str) abc]
 > say $CC.I[1];
abc
 > $CC.I[0] = "zyz";
zyz
 > say $CC.I;
[zyz abc]
 >


Hi Norman,

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

Reply via email to