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

On Tue, Jul 6, 2021 at 9:39 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> 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
>
>

-- 
Fernando Santagata

Reply via email to