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
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
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
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):
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
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
> 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]
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
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
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.
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
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).
>
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;
>
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
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.
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 () {
> 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
17 matches
Mail list logo