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

sequence operator '...' timeout #2477

Closed
p6rt opened this issue Sep 21, 2011 · 11 comments
Closed

sequence operator '...' timeout #2477

p6rt opened this issue Sep 21, 2011 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Sep 21, 2011

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

Searchable as RT99658$

@p6rt
Copy link
Author

p6rt commented Sep 21, 2011

From redicaps@gmail.com

(13​:50​:48) woosley​: rakudo​: my @​a = 1,3,5 ... *; say @​a[^4]
(13​:50​:49) p6eval​: rakudo f1c805​: OUTPUT«1 3 5 7␤»

(13​:46​:40) woosley​: perl6​: my @​odd = 1,3,5 ... 8; say @​odd[^4]
(13​:47​:05) p6eval​: rakudo f1c805, niecza v9-32-g380d891​: OUTPUT«(timeout)»

according to S03, '1,3,5 ... 8' should act as '1,3,5 ... *'

--
woosley.xu.

@p6rt
Copy link
Author

p6rt commented May 28, 2012

From @coke

On Tue Sep 20 23​:03​:06 2011, woosley.xu wrote​:

(13​:50​:48) woosley​: rakudo​: my @​a = 1,3,5 ... *; say @​a[^4]
(13​:50​:49) p6eval​: rakudo f1c805​: OUTPUT«1 3 5 7␤»

(13​:46​:40) woosley​: perl6​: my @​odd = 1,3,5 ... 8; say @​odd[^4]
(13​:47​:05) p6eval​: rakudo f1c805, niecza v9-32-g380d891​: OUTPUT«(timeout)»

according to S03, '1,3,5 ... 8' should act as '1,3,5 ... *'

S03 now says the opposite​:

--
Likewise, this is all of the even numbers​:

  my $end = 7;
  0,2,4 ... $end
--

Rejecting ticket.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented May 28, 2012

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

@p6rt
Copy link
Author

p6rt commented May 28, 2012

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

@p6rt
Copy link
Author

p6rt commented May 28, 2012

From @coke

On Sun May 27 21​:13​:06 2012, coke wrote​:

On Tue Sep 20 23​:03​:06 2011, woosley.xu wrote​:

(13​:50​:48) woosley​: rakudo​: my @​a = 1,3,5 ... *; say @​a[^4]
(13​:50​:49) p6eval​: rakudo f1c805​: OUTPUT«1 3 5 7␤»

(13​:46​:40) woosley​: perl6​: my @​odd = 1,3,5 ... 8; say @​odd[^4]
(13​:47​:05) p6eval​: rakudo f1c805, niecza v9-32-g380d891​: OUTPUT«(timeout)»

according to S03, '1,3,5 ... 8' should act as '1,3,5 ... *'

S03 now says the opposite​:

--
Likewise, this is all of the even numbers​:

my $end = 7;
0,2,4 \.\.\. $end

--

Rejecting ticket.

Whops. This isn't the opposite of what you said, ti's the same thing.

Reopening ticket.

(note to self, don't wrangle tickets at this hour.)

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented May 28, 2012

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

@p6rt
Copy link
Author

p6rt commented Sep 23, 2014

From @usev6

Actually I don't think S03 says that '1,3,5 ... 8' should act as '1,3,5 ... *'

As I understand it '1,3,5 ... 8' gives an infinite list with all even numbers. '1,3,5 ... *' also gives an infinite list with all even numbers -- but this one is lazy.

So there is a difference in behaviour​: When assigning to an array with 'my @​odd = 1,3,5 ... 8;' all elements of the sequence have to be computed and smart matched agains '8'. This match never results in True and therefore we get a timeout, finally. In the other case ('my @​odd = 1,3,5 ... *') "the sequence has no limit" (quote from S03) and the assignment can be lazy e.g. the values don't have to be computed and smart matched against something.

S03 explicitly notes​:

==== quote
If a limit is given, it must smartmatch exactly. If it does not, an infinite list results. For instance, since "asymptotically approaching" is not the same as "equals", both of the following are infinite lists, as if you'd specified * for the limit rather than 0​:

  1,1/2,1/4 ... 0 # like 1,1/2,1/4 ... *
  1,-1/2,1/4 ... 0 # like 1,-1/2,1/4 ... *

Likewise, this is all of the even numbers​:

  my $end = 7;
  0,2,4 ... $end

To catch such a situation, it is advised to write an inequality instead​:

  0,2,4 ...^ { $_ > $end }
==== quote end

One note to the original command

my @​odd = 1,3,5 ... 8; say @​odd[^4]

We can get around the assignment to @​odd and thereby stay lazy​:

(1,3,5 ... 8)[^4] ## works
1 3 5 7
(1,3,5 ... *)[^4] ## same as above
1 3 5 7

So IMHO this is not a bug (and the ticket could be closed).

@p6rt
Copy link
Author

p6rt commented Oct 16, 2014

From @masak

bartolin (>)​:

Actually I don't think S03 says that '1,3,5 ... 8' should act as
'1,3,5 ... *'

As I understand it '1,3,5 ... 8' gives an infinite list with all even
numbers. '1,3,5 ... *' also gives an infinite list with all even
numbers -- but this one is lazy.

So there is a difference in behaviour​: When assigning to an array with
'my @​odd = 1,3,5 ... 8;' all elements of the sequence have to be
computed and smart matched agains '8'. This match never results in
True and therefore we get a timeout, finally. In the other case ('my
@​odd = 1,3,5 ... *') "the sequence has no limit" (quote from S03) and
the assignment can be lazy e.g. the values don't have to be computed
and smart matched against something.

I think this reasoning is sound, and whereas it would be awesome if we could always read the mind of the user and not get stuck in infinite loops trying to compute infinite sequences -- the place we are is kind of a local minimum and has an internal consistency.

That is, we could perhaps do better in the future, and not hang on this one. But it's not clear to me how to do that without making the current model more complex for relatively little gain.

Rejecting ticket.

@p6rt
Copy link
Author

p6rt commented Oct 16, 2014

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

@p6rt p6rt closed this as completed Oct 16, 2014
@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From 1parrota@gmail.com

Wouldn't "1,3,5,7" be a more reasonable result? The next value, "9" is
greater than the end term, so it should stop?

On 10/16/14, Carl Mäsak via RT <perl6-bugs-followup@​perl.org> wrote​:

bartolin (>)​:

Actually I don't think S03 says that '1,3,5 ... 8' should act as
'1,3,5 ... *'

As I understand it '1,3,5 ... 8' gives an infinite list with all even
numbers. '1,3,5 ... *' also gives an infinite list with all even
numbers -- but this one is lazy.

So there is a difference in behaviour​: When assigning to an array with
'my @​odd = 1,3,5 ... 8;' all elements of the sequence have to be
computed and smart matched agains '8'. This match never results in
True and therefore we get a timeout, finally. In the other case ('my
@​odd = 1,3,5 ... *') "the sequence has no limit" (quote from S03) and
the assignment can be lazy e.g. the values don't have to be computed
and smart matched against something.

I think this reasoning is sound, and whereas it would be awesome if we could
always read the mind of the user and not get stuck in infinite loops trying
to compute infinite sequences -- the place we are is kind of a local minimum
and has an internal consistency.

That is, we could perhaps do better in the future, and not hang on this one.
But it's not clear to me how to do that without making the current model
more complex for relatively little gain.

Rejecting ticket.

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @pmichaud

On Fri Oct 17 09​:34​:45 2014, 1parrota@​gmail.com wrote​:

Wouldn't "1,3,5,7" be a more reasonable result? The next value, "9" is
greater than the end term, so it should stop?

Not all sequences are increasing, or even monotonic, or even numeric. We've not found any guide for inexact termination points that is reliable enough to use, or better than the recommended (and explicit)​:

  1, 3, 5, ... * >= 8

Pm

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