Questions tagged [infinite-sequence]
24 questions
17
votes
2 answers
Whats the point of lazy-seq in clojure?
I am looking through some example Fibonacci sequence clojure code:
(def fibs (lazy-cat [1 2] (map + fibs (rest fibs))))
I generally understand what is going on, but don't get the point of lazy-cat.
I know that lazy-cat is a macro that is…

dbyrne
- 59,111
- 13
- 86
- 103
10
votes
10 answers
Iterate over an infinite sequence in Ruby
I am trying to solve Project Euler problem #12:
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number
would be 1 + 2 + 3 + 4 + 5 + 6 + 7 =
28. The first ten terms would be:
1, 3, 6, 10, 15,…

nikhil
- 8,925
- 21
- 62
- 102
10
votes
4 answers
linq infinite list from given finite list
Given a finite list of elements, how can I create a (lazily-evaluated, thanks LINQ!) infinite list that just keeps iterating over my initial list?
If the initial list is {1, 2, 3}, I want the new list to return {1, 2, 3, 1, 2, 3, 1, ...}

Cristian Diaconescu
- 34,633
- 32
- 143
- 233
9
votes
5 answers
How to cut a for-comprehension short (break out of it) in scala?
I have a piece of code which would code as follows:
val e2 = for (e <- elements if condition(expensiveFunction(e))) yield {
expensiveFunction(e)
}
Where the condition will be true for a few elements and then become false for…

jsalvata
- 2,155
- 15
- 32
7
votes
5 answers
Linq statement for an infinite sequence of successive halves
Given a starting number, imagine an infinite sequence of its successive halves.
1, 0.5, 0.25, 0.125, ...
(Ignore any numerical instabilities inherent in double.)
Can this be done in a single expression without writing any custom extension methods…

Drew Noakes
- 300,895
- 165
- 679
- 742
5
votes
3 answers
Implementing an infinite list of consecutive integers in Lisp for lazy evaluation
Prelude
In Raku there's a notion called infinite list AKA lazy list which is defined and used like:
my @inf = (1,2,3 ... Inf);
for @inf { say $_;
exit if $_ == 7 }
# => OUTPUT
1
2
3
4
5
6
7
I'd like to implement this sort of thing in…

Lars Malmsteen
- 738
- 4
- 23
5
votes
3 answers
Consequences of an infinite loop on Google App Engine?
I am not a Google App Engine user. However, I understand you're billed for CPU time and other resources. What are the consequences if you happen to create an infinite loop? Will Google ever terminate it, or will you have to do it yourself manually…

doppelgreener
- 4,809
- 10
- 46
- 63
4
votes
3 answers
Remove consecutive duplicates from an infinite list via folding?
Consider one of these implementations of a function to remove consecutive duplicates from a list:
uniq :: Eq a => [a] -> [a]
uniq [] = []
uniq (x:xs) = x:uniq (dropWhile (x ==) xs)
uniq :: Eq a => [a] -> [a]
uniq (x:xs@(y:_))
| x == y = x:tail…

Joseph Sible-Reinstate Monica
- 45,431
- 5
- 48
- 98
4
votes
2 answers
Infinite ascending sequence in Racket
Is there an analog of Python's itertools.count in Racket? I want to create an infinite stream of evenly spaced numbers. in-naturals is similar to what i want, but does not provide step. I'd want not to reinvent the wheel, but if there's no…

Mirzhan Irkegulov
- 17,660
- 12
- 105
- 166
3
votes
1 answer
WPF ListBox generate items as user scrolls
I am trying to use a ListBox to display a possibly infinite list of options to a user. Currently, I am simply cutting off the list at an arbitrary point, but I would like to allow the user to scroll down as far as they want. Also, I want to avoid…

perelman
- 1,747
- 14
- 25
2
votes
3 answers
Generating an infinite sequence in Haskell
I know that infinite sequences are possible in Haskell - however, I'm not entirely sure how to generate one
Given a method
generate::Integer->Integer
which take an integer and produces the next integer in the sequence, how would I build an infinite…

Martin
- 12,469
- 13
- 64
- 128
2
votes
2 answers
Construction of infinite list in Haskell
I have two things for the desired infinite list: its first element
x :: A
and function which generates the next element
f :: [A] -> A
What's the best (most idiomatic? fastest?) way to create infinite list? I mean
xs = x : f [x] : f [x, f [x]] : f…

aplavin
- 2,199
- 5
- 32
- 53
1
vote
2 answers
A simple For loop to print partial sums of infinite sequence gives error: replacement has length zero
A simple problem in R using the For loop to compute partial sums of an infinite sequence is running into an error.
t <- 2:20
a <- numeric(20) # first define the vector and its size
b <- numeric(20)
a[1]=1
b[1]=1
for (t in seq_along(t)){
…

user11254108
- 95
- 6
1
vote
2 answers
Capture indefinite amount of numbers with Regex?
I want to get captures using regex on a string that could contain an indefinite amount of numbers. My intuition lead me to do "/\.getnumbers (\d+)+\s*/"but that only matched the first number following the .getnumbers command. How do I write a regex…

Reznor
- 1,235
- 5
- 14
- 23
1
vote
3 answers
infinite sequence scheme to make infinite sequence
I have a project in scheme in which I need to implement an infinite sequence of numbers. I can't use any scheme-built-in complex functions, and I just do not know how to make my sequence infinite without program crashing in infinite loop. I don't…

mooly
- 113
- 1
- 8