Navigation Menu

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

Can(not) assign to List #4499

Closed
p6rt opened this issue Sep 2, 2015 · 4 comments
Closed

Can(not) assign to List #4499

p6rt opened this issue Sep 2, 2015 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 2, 2015

Migrated from rt.perl.org#125963 (status was 'rejected')

Searchable as RT125963$

@p6rt
Copy link
Author

p6rt commented Sep 2, 2015

From @FROGGS

This feels rather inconsistent​:

m​: my $a = (1, 2, 3); say $a; say $a.WHAT; $a[1] = 42
rakudo-moar 467b79​: OUTPUT«(1 2 3)␤(List)␤Cannot modify an immutable
Int␤ in block <unit> at /tmp/46mt71Ed8W​:1␤␤»

m​: my $a = [1, 2, 3]; say $a = $a[*]; say $a.WHAT; $a[1] = 42; say $a
rakudo-moar 467b79​: OUTPUT«(1 2 3)␤(List)␤(1 42 3)␤»

@p6rt
Copy link
Author

p6rt commented Sep 4, 2015

From @jnthn

On Wed Sep 02 05​:06​:50 2015, FROGGS.de wrote​:

This feels rather inconsistent​:

m​: my $a = (1, 2, 3); say $a; say $a.WHAT; $a[1] = 42
rakudo-moar 467b79​: OUTPUT«(1 2 3)␤(List)␤Cannot modify an immutable
Int␤ in block <unit> at /tmp/46mt71Ed8W​:1␤␤»

Here, you have a List of three literal Int objects. And Int is not a container and cannot be assigned to.

m​: my $a = [1, 2, 3]; say $a = $a[*]; say $a.WHAT; $a[1] = 42; say $a
rakudo-moar 467b79​: OUTPUT«(1 2 3)␤(List)␤(1 42 3)␤»

Here you have a List of 3 Scalar containers, which happen to contain Ints. Indexing an array has to return its containers, since that's what makes an array element assignable. And that is why you can assign here. It's the same reason that​:

($x, $y) = 3, 4;

Also works, but​:

(1, 2) = 3, 4;

Does not.

@p6rt
Copy link
Author

p6rt commented Sep 4, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Sep 4, 2015
@p6rt
Copy link
Author

p6rt commented Sep 4, 2015

@jnthn - Status changed from 'open' to 'rejected'

@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