Skip to content
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

Arrays passed through *%_ and stored into attributes get an extra layer of Array around them in Rakudo #1169

Closed
p6rt opened this issue Jul 25, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 25, 2009

Migrated from rt.perl.org#67872 (status was 'resolved')

Searchable as RT67872$

@p6rt
Copy link
Author

p6rt commented Jul 25, 2009

From @masak

<masak> rakudo​: class A { has @​!a; method foo { .say for @​!a.elems,
@​!a.perl } }; sub bar(*%_) { A.new(|%_) }; my @​b = 42,43,44;
bar(​:a(@​b)).foo
<p6eval> rakudo dd5767​: OUTPUT«1␤[[42, 43, 44]]␤»
<masak> when arrays are passed through *%_, they get an extra layer of
array around them.
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Jul 25, 2009

From @masak

<pmichaud> that actually seems right to me
<pmichaud> because the value portion of a pair is a scalar
<pmichaud> and placing an array into a scalar creates a reference
<pmichaud> (modulo any new capture/parcel semantics)
<masak> pmichaud​: ok. let's say I want to have an array in my @​!a.
<masak> (and I need to use *%_ because I'm passing unknown things along)
<masak> how do I do it?
<pmichaud> I don't know.
<pmichaud> I'm not arguing in favor of the current semantics -- I'm just
having trouble seeing how they ought to work
<masak> it works without the *%_ step. or without the class/attr.
<pmichaud> well, the %* definitely converts pairs into a hash
<masak> and yet, this works​:
<masak> rakudo​: sub foo(​:@​a) { say @​a.elems }; sub bar(*%_) { foo(|%_)
}; my @​b = 42,43,44; bar(​:a(@​b))
<p6eval> rakudo dd5767​: OUTPUT«3␤»
<pmichaud> okay, it must be something in .new then
<masak> it's only when this is combined with storing the array into an
attr in an object that the extra layer of array is added.
* masak adds this to the bug ticket
<pmichaud> my guess is going to be that :a(@​b) builds a named argument
with a capture
<pmichaud> interestingly, though, that would mean that changes to @​b
would affect the named argument

@p6rt
Copy link
Author

p6rt commented Jul 25, 2009

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 28, 2009

From @masak

On Sat Jul 25 02​:31​:10 2009, masak wrote​:

<masak> rakudo​: class A { has @​!a; method foo { .say for @​!a.elems,
@​!a.perl } }; sub bar(*%_) { A.new(|%_) }; my @​b = 42,43,44;
bar(​:a(@​b)).foo
<p6eval> rakudo dd5767​: OUTPUT«1␤[[42, 43, 44]]␤»
<masak> when arrays are passed through *%_, they get an extra layer of
array around them.
* masak submits rakudobug

Nowadays, in Rakudo 6a43a3, this problem doesn't manifest itself​:

$ perl6 -e 'class A { has @​!a; method foo { .say for @​!a.elems, @​!a.perl } }; sub bar(*%_) {
A.new(|%_) }; my @​b = 42,43,44; bar(​:a(@​b)).foo'
3
[42, 43, 44]

Resolving ticket.

@p6rt p6rt closed this as completed Oct 28, 2009
@p6rt
Copy link
Author

p6rt commented Oct 28, 2009

@masak - Status changed from 'open' to 'resolved'

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant