Re: Perl 5 list assignment idiom

2021-11-13 Thread rir
On Mon, Mar 13, 2017 at 11:32:25AM -0700, Sean McAfee wrote: > In Perl 5 ... > 1 == (my ($script) = $page->find('//script')) > or die "Other than exactly one script element found"; > Can a similar expression that avoids an intermediate array variable be > written in Perl 6? This

Re: list assignment

2021-01-20 Thread Parrot Raiser
The fundamental problem here seems to be the imprint of Perl's behaviour on the mental model. Assigning arrays flattens them into a list of their contents, which then gets used as input to the assignment. That means that more complicated structures, such as arrays of arrays need some faking. Raku

Re: list assignment

2021-01-19 Thread Ben Davies
On 2021-01-19 2:18 p.m., Brian Duggan wrote: Hi Folks, I ran into this situation today, which seems counterintuitive: my @one = 1,2,3; my @two = 4,5,6; my @both = @one,@two; my @first = @both[0]; say @one.raku; say @first.raku; output: [1, 2, 3] [[1, 2, 3],] I

Re: list assignment

2021-01-19 Thread William Michels via perl6-users
Hi Brian (and Bruce), Just a short note to say that we had a conversation entitled "Extra . needed" on this mailing list a few weeks ago, for which the solution (per Brad Gilbert) was a sort of "double-dereferencing" (for lack of a better terminology):

Re: list assignment

2021-01-19 Thread Ralph Mellor
Food for thought... Python: one = 1,2,3 two = 4,5,6 both = one,two first = both[0] print(one) # (1, 2, 3) print(first) # (1, 2, 3) Python's `=` operator is like Raku's `:=`. my @one := 1,2,3; my @two := 4,5,6; my @both := @one,@two; my @first := @both[0]; say @one.raku; # (1, 2, 3) say

Re: list assignment

2021-01-19 Thread Brian Duggan
Thanks everyone for the thoughtful replies. I think this helped me the most -- On Tuesday, January 19, Vadim Belman wrote: > We have a documentation section on this: > https://docs.raku.org/language/list#Itemization "itemization in Arrays is assumed" ... "It was decided all those

Re: list assignment

2021-01-19 Thread Bruce Gray
> On Jan 19, 2021, at 12:18 PM, Brian Duggan wrote: > > Hi Folks, > > I ran into this situation today, which seems counterintuitive: > > my @one = 1,2,3; > my @two = 4,5,6; > my @both = @one,@two; > my @first = @both[0]; > say @one.raku; > say @first.raku; > > output: > > [1, 2, 3]

Re: list assignment

2021-01-19 Thread Vadim Belman
Hi, I would like to give a perspective a bit different to what yary provided. Your example here can be golfed down to: my $a = [1,2,3]; my @v = $a; say @v; # [[1,2,3],] The reason for this behavior is $a being a scalar container. Correspondingly, when you assign it to @v the assignment op

Re: list assignment

2021-01-19 Thread ToddAndMargo via perl6-users
On 1/19/21 10:42 AM, yary wrote: Let's dig in a little  my @one = 1,2,3;  my @two = 4,5,6;  my @both = @one,@two; at this point @both is an array containing two arrays > dd @both Array @both = [[1, 2, 3], [4, 5, 6]] Showing that assigning into an array variable gives an array, each

Re: list assignment

2021-01-19 Thread yary
Let's dig in a little my @one = 1,2,3; my @two = 4,5,6; my @both = @one,@two; at this point @both is an array containing two arrays > dd @both Array @both = [[1, 2, 3], [4, 5, 6]] Showing that assigning into an array variable gives an array, each element of which can itself be an array.

list assignment

2021-01-19 Thread Brian Duggan
Hi Folks, I ran into this situation today, which seems counterintuitive: my @one = 1,2,3; my @two = 4,5,6; my @both = @one,@two; my @first = @both[0]; say @one.raku; say @first.raku; output: [1, 2, 3] [[1, 2, 3],] I was expecting @first and @one to be the same. I

Re: Basic question about lexical binding in relationship with "list assignment"

2019-01-02 Thread Elizabeth Mattijsen
an outer symbol; the implicit outer binding > must be rewritten as OUTER::<$foo> before you can unambiguously declare > a new '$foo' in this scope. > > This will compile with Perl 5 when I add 'use v5.14;' at the top and it > will then print 3, then 3 then 6 (as expected). >

Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread Elizabeth Mattijsen
ambiguously declare > a new '$foo' in this scope. > > This will compile with Perl 5 when I add 'use v5.14;' at the top and it > will then print 3, then 3 then 6 (as expected). > > Well, it seems that I can 'cheat' by simply doing a list assignment: > >my $foo = 3; >

Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread JJ Merelo
then print 3, then 3 then 6 (as expected). > > Well, it seems that I can 'cheat' by simply doing a list assignment: > > my $foo = 3; > say $foo; > > { > say $foo; > > my ($foo) = 6; # avoid `... '$foo' is already bound ...' > That should mak

Re: Perl 5 list assignment idiom

2017-03-13 Thread Brock Wilcox
The == operator coerces to Numeric, so like: > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|93867233982256) ... } > one-thing.Numeric 1 (mentioned in https://docs.perl6.org/routine/$EQUALS_SIGN$EQUALS_SIGN) I think my does indeed do some fancy precidenting with the assignment.

Re: Perl 5 list assignment idiom

2017-03-13 Thread Sean McAfee
On Mon, Mar 13, 2017 at 12:37 PM, Will Coleda wrote: > Works the same in Perl 6, and you can avoid the parens. Using helper > subs that return one or two item lists, here's some sample code: > > $ perl6 > > sub one-thing { return ("hi",) } > sub one-thing () {

Re: Perl 5 list assignment idiom

2017-03-13 Thread Will Coleda
> sub two-things { return } sub two-things () { #`(Sub|140454852044088) ... } > 1 == my $bar = two-things False > $bar (hi there) On Mon, Mar 13, 2017 at 2:32 PM, Sean McAfee <eef...@gmail.com> wrote: > In Perl 5, list assignment in scalar context evaluates to the number of l