New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%c = %a, %b and @c = @a, @b should behave similarly #6178
Comments
From @AlexDanielCode: Result: So with arrays, nothing is flattened and you get an array with two elements. Makes sense. And if we want to get a different behavior, we can use slip: Code: Result: Everything is fine so far. Now, let's try the same thing with hashes: Code: Result: To me that looks like an inconsistency, I would have expected it to create a hash with one pair (%a => %b). In fact, both 「%c = %a, %b」 and 「%c = |%a, |%b」 work exactly the same! The idea of %a => %b may seem weird, but it really isn't if you consider object hashes (my %c{Hash} = %a => %b; or even my %c{Hash} = Another thing to note is that this array behavior was changed during the GLR, but hashes remained the same. Perhaps that was an oversight. |
From @geekosaurIIRC this hash behavior is deliberate so that hashes can be accumulated. On Thu, Apr 6, 2017 at 4:46 PM, Aleks-Daniel Jakimenko-Aleksejev <
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @zoffixznetOn Thu, 06 Apr 2017 13:46:00 -0700, alex.jakimenko@gmail.com wrote:
The overwhelming majority of usecases would want merged hashes, not a hash keyed on another hash. Also, there is consistency with Pairs: m: my %h = :2a, :3a; dd %h Why would `Hash, Hash` end up as keyed on a Hash, when `Pair, Pair` gets merged? This parallel is much closer than the Array one, so I'd argue it overrules the inconsistency with more distant types. |
From @jnthnOn Thu, 06 Apr 2017 13:46:00 -0700, alex.jakimenko@gmail.com wrote:
I certainly considered this matter during the course of the GLR, and felt that trying to make the two assignment cases behave the same would count as a foolish consistency. And it's not like there wasn't already precedent for assignment to vary in its rules by sigil. After all, list and item assignment parse at difference precedence levels - which is arguably a much bigger difference than a different choice over flattening! In fact, it's pretty consistent throughout Perl 6 that you need to know about the target of an assignment in order to know what it's going to do with the source. Assignment into a List like `($a, $b) = @c` will happily discard unused values, while assignment into a fixed size array will complain if there's too many items. If it's a multi-dimensional array then it will look for the shape to be replicated in the source, and complain if it's not "close enough" (so that's another case where a nested structure on the right will get special treatment). So even within list-space, we have differing assignment semantics based upon the target. /jnthn |
From @cokeOn Fri, 07 Apr 2017 06:07:58 -0700, jnthn@jnthn.net wrote:
Based on jnthn's comment here, rejecting the ticket. -- |
@coke - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#131111 (status was 'rejected')
Searchable as RT131111$
The text was updated successfully, but these errors were encountered: