develooper Front page | perl.perl6.users | Postings from July 2021

Re: How do a pe-salt an array inside an object?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
July 6, 2021 07:39
Subject:
Re: How do a pe-salt an array inside an object?
Message ID:
cad7e341-e7de-0444-19d8-70e53b12d2a3@zoho.com
>> On Tue, 6 Jul 2021 at 10:55, ToddAndMargo via perl6-users 
>> <perl6-users@perl.org <mailto:perl6-users@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


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About