m_turner has asked for the wisdom of the Perl Monks concerning the following question:
And that worked. Adding a Junction to this:my @list = (1, 2, 3); my $sum = [+] @list; say $sum;
And that spat out an error: "Type check failed in assignment to $sum; expected Numeric but got Junction (any(3, 4))"my @list = (1, 2|3, 4); my $sum = [+] @list; say $sum;
Switching this code to another form of list summation
That works fine.my @list = (1, 2|3, 4); my $sum = @list.reduce(*+*); say $sum;
This mismatch of expectations and errors also occurs with $sum = @list.sum; when there is a Junction in the list. So, what I'm wondering is "what is the difference between these invocations?" I suspect its something with the type system that I haven't wrapped my head around yet and that it is working as expected.
It's also quite possible that I'm introducing an XY problem in to this and that I shouldn't be doing it this way in the first place - and if that's the case, a pointer off to the more idiomatic way of dealing with what looks to be a good fit for the ace = 1|11 state would be appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [+] on a list... with a Junction
by Zoffix (Acolyte) on Nov 23, 2016 at 11:14 UTC | |
by m_turner (Sexton) on Nov 24, 2016 at 03:42 UTC | |
by Zoffix (Acolyte) on Nov 25, 2016 at 19:42 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |