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

Assigning multiple values to an array does not work with infinite ranges (@a[^∞] = 42) #5199

Closed
p6rt opened this issue Mar 25, 2016 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Mar 25, 2016

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

Searchable as RT127784$

@p6rt
Copy link
Author

p6rt commented Mar 25, 2016

From @AlexDaniel

Let's start with an example that works​:

Code​:
my @​a;
@​a[^8] = 5, 6;
say @​a

Result​:
[5 6 (Mu) (Mu) (Mu) (Mu) (Mu) (Mu)]

That's fine. But let's try an infinite range now​:

Code​:
my @​a;
@​a[^â��] = 5, 6;
say @​a

Result​:
[]

That's definitely not what I meant.

<timotimo> i'd expect the latter to have 5, 6 in it and no Mu afterwards

Yes, that's what I expected too. But I can also accept an error that says �I can't do it�.

@p6rt
Copy link
Author

p6rt commented Mar 30, 2016

From @jnthn

On Fri Mar 25 11​:53​:59 2016, alex.jakimenko@​gmail.com wrote​:

Let's start with an example that works​:

Code​:
my @​a;
@​a[^8] = 5, 6;
say @​a

Result​:
[5 6 (Mu) (Mu) (Mu) (Mu) (Mu) (Mu)]

That's fine. But let's try an infinite range now​:

Code​:
my @​a;
@​a[^â��] = 5, 6;
say @​a

Result​:
[]

That's definitely not what I meant.

We've been around the block a few times on this one, and the current semantics that you observe here are the ones we've settled on, so this is not a bug. But to explain why things are this way...

Note also that​:

$ perl6-m -e "my @​a; @​a[lazy ^8] = 5, 6; say @​a;"
[]

The iterator of ^� considers itself wanting lazy evaluation, and this lazy marking is what we use to decide between truncating at the current length of the array (lazy) or taking the range at face value and indexing all the elements (non-lazy).

For a while, we always trimmed ranges at the length of the array, meaning​:

@​a[0,1] = <a b>;

Would assign, and​:

@​a[^1] = <a b>;

Would do nothing. We fixed that to make the above two equivalent, which is a lot less surprising, and by hanging it off the laziness peg we still let @​a[2..*] (or @​a[2..Inf]) truncate as expected when slicing.

Note that since l-values are first class in Perl 6, we can't in general know whether a given indexing is going to be used as an l-value or not, so making​:

@​a[^â��] = ...

Do something different to​:

... = @​a[^â��]

Is also not an option. And I think we can agree that r-value auto-truncating is highly useful. Also note that slicing in and of itself is an eager operation.

Thanks,

/jnthn

@p6rt
Copy link
Author

p6rt commented Mar 30, 2016

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

@p6rt p6rt closed this as completed Mar 30, 2016
@p6rt
Copy link
Author

p6rt commented Mar 30, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant