Front page | perl.perl6.users |
Postings from August 2021
Re: (sigils are awesome, they say ...) Re: pairs of separators froma string
Thread Previous
|
Thread Next
From:
yary
Date:
August 23, 2021 14:27
Subject:
Re: (sigils are awesome, they say ...) Re: pairs of separators froma string
Message ID:
CAG2CFAbwpkrD6S4Q0-YQ_o6W+PLrCuJ5G2gkzJ8bx5ZoSeBQjg@mail.gmail.com
A little more of Vadim's example
> my $a = <a b c>; say $a.raku;
("a", "b", "c")
> my @a = <a b c>; say @a.raku;
["a", "b", "c"]
> @a[1]='X'; say @a.raku;
["a", "X", "c"]
> $a[1]='X'
Cannot modify an immutable List ((a b c))
in block <unit> at <unknown file> line 1
$a is a scalar container, holds one thing. In this example a List - raku
shows as parens.
@a is an array of scalar containers, each of which can be reassigned. Raku
shows as square brackets.
See https://docs.raku.org/language/containers for this plus discussion on
binding
> my @b := (7,6,5); say @b.raku
(7, 6, 5)
> @b[1]='X'
Cannot modify an immutable List ((7 6 5))
in block <unit> at <unknown file> line 1
-y
On Sun, Aug 22, 2021 at 3:38 PM Vadim Belman <vrurg@lflat.org> wrote:
>
> Sigils mean a lot. For example, they create a context:
>
> my $a = 1,2,3;
> my @a = 1,2,3;
> $a = <a b c>; say $a.raku;
> @a = <a b c>; say @a.raku;
>
> If you have some (actually, a lot of) spare time you can watch my class
> from TRC2021 where I cover a lot about symbols/sigils/object interaction in
> Raku:
>
> https://conf.raku.org/talk/154
> https://conf.raku.org/talk/163
>
>
> Best regards,
> Vadim Belman
>
> On Aug 22, 2021, at 8:57 AM, Marc Chantreux <eiro@phear.org> wrote:
>
> thanks everyone for sharing,
>
> Vadim,
>
> my ($a, $b) = { @^a[0,2...Inf], @a[1,3...Inf] }.(q<(){}[]>.comb); say
> $a[0]; say $b[0]
>
> oh. i never see this direct call of a lambda before but it really makes
> sense! this is the answer i like the most.
>
> i rewrote it my way and this works
>
> my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.(q<AABBCCDD>.comb);
>
> it would be nice if this one will:
>
> my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.: q<AABBCCDD>.comb;
>
> But here is one of the reasons i'm still unconfortable with raku is the
> fact that sigils don't make sense anymore to me (in the contrary of perl
> were sigils means "i want a [$%@] from this").
>
> so as i can't get grid of sigils in this case
>
> my (\a, \b) = { .[0,2…∞], .[1,3…∞] }.(q<AABBCCDD>.comb);
>
> i need to choose a sigil. The way i understand sigils is
> "an optional type specifier". to me
>
> my $truc => my container 'truc' for anything you want
> my @truc => my container 'truc' for something that should mostly
> be understood as indexed
> my %truc => my container 'truc' for something that should mostly
> be understood as associative
>
> so of course i tried
>
> my (@a, @b) = { .[0,2…∞], .[1,3…∞] }.(q<AABBCCDD>.comb);
>
> because i have two lists and two containers. this doesn't work.
> which means @ and $ combines with = to define how things are stored
> but i don't understand how for the moment.
>
> regards,
> marc
>
>
>
Thread Previous
|
Thread Next