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
In a recursive List, should a term be allowed to depend on a later term? #3005
Comments
From tim.bollman@live.comRakudo Version: 2012.12-38-gc8de2eb Story: I was attempting to write a different solution to the Collatz Sequence problem in this years Advent Calendar. I figured it was a sequence of numbers, the sequence operation should be able to rock this problem efficiently. I'm not sure if this is supposed to be supported by the implementation, but if it is, I believe the problem comes down to Rakudo not liking to vivify later elements in the sequence in order to vivify the current element. Works:
Doesn't Work: -Tim
|
From mark@kli.orgIt isn't so much computing later values in the sense of higher numbered ones. It's computing ones that haven't been computed yet. The first example doesn't work either, if you don't access the values sequentially:
(On my system the error string is in an endless loop) When you accessed it with ^5, you allowed each element to be computed before it was needed by others. It doesn't have to be linear:
|
The RT System itself - Status changed from 'new' to 'open' |
From @cokeOn Sun Dec 23 16:28:31 2012, TimTom wrote:
Neither of these work now (2016.07.1) The first outputs: (Inf 1 (...) Nil Nil Nil) And the second ===SORRY!=== Error while compiling /Users/coke/p6 -- |
From @smlsThe first one still works in current Rakudo if you add a | to slip the `map` sequence into the parent list. ➜ my @collatz = Inf, 1, |(2 .. *).map: { @collatz[$_ - 1] + 1 }; say @collatz[0 .. 5]; As for the second one, after giving it the same treatment (and fixing its two syntax typos), it simply hangs indefinitely after the third term: ➜ my @collatz = Inf, 1, |(2 .. *).map: { $_ %% 2 ?? @collatz[$_ div 2] !! @collatz[3 * $_ + 1] }; say @collatz[$_] for 0 .. 5; So it seems that Timothy Bollman's key observation in the original ticket is still correct: Rakudo won't reify a later term of a sequence, in order to reify an earlier term. I have no idea if it *should* work (ask TimToady), or if it would even be feasible given how lists/sequences work (ask jnthn). |
From @smlsHere is a simpler test-case demonstrating the issue (i.e. recursive out-of-order reification not working): ➜ my @a = (0..*).map({ $_ == 0 ?? 10 !! 5 }); say @a[^5]; ➜ my @a = (0..*).map({ $_ == 0 ?? 2 * @a[1] !! 5 }); say @a[^5]; # This one generates junk results ➜ my @a = (0..*).map({ $_ %% 2 ?? 2 * @a[$_ + 1] !! 5 }); say @a[^5]; # This one hangs |
Migrated from rt.perl.org#116186 (status was 'open')
Searchable as RT116186$
The text was updated successfully, but these errors were encountered: