Questions tagged [lazy-sequences]

Lazy sequences are sequences that are constructed as their members are accessed.

Lazy sequences are sequences that are constructed as their members are accessed.

For example, all haskell sequences are lazy because of the lazy semantics of the language; python's generators can also be considered lazy sequences.

273 questions
1
vote
1 answer

Lazy Fibonacci Sequence in Ruby

Coming from Python if I wanted to create an iterative lazy Fibonacci sequence, I could do something like this: def fib(): a = 1 b = 2 yield a yield b while True: yield a + b tmp = a a = b b = tmp +…
Chris
  • 4,425
  • 5
  • 34
  • 49
1
vote
2 answers

Can an echo program in Clojure be built with lazy infinite sequences?

Take the following program as an example: (defn echo-ints [] (doseq [i (->> (BufferedReader. *in*) (line-seq) (map read-string) (take-while integer?))] (println i))) The idea is to prompt the…
Sebastian Oberhoff
  • 1,271
  • 1
  • 10
  • 16
1
vote
1 answer

How do I create a call-by-need list with increasing size in Standard ML?

I am trying to create a lazy list with list elements which together represent all the combinations of zeros and ones. Example: [[], [0], [1], [0,0], [0,1], [1,0]...] Is this even possible in ML? I can't seem to find a way to change the pattern of…
oldselflearner1959
  • 633
  • 1
  • 5
  • 22
1
vote
1 answer

Trying to understand Kotlin Example

I want to learn Kotlin and am working through the Examples on try.kotlinlang.org I have trouble understanding some examples, particularly the Lazy property example:…
abinmorth
  • 527
  • 2
  • 8
  • 25
1
vote
1 answer

How to force evaluation of lazy seqs in Clojure when running from an uberjar?

Consider the following MWE: (ns toto.core (:gen-class)) (defn write-something [i] (spit (str "out-" (str i) ".txt") "Hi there!")) (defn -main "I don't do a whole lot ... yet." [& args] (dorun (pmap write-something (range 16)))) If I run…
mvarela
  • 209
  • 1
  • 3
  • 8
1
vote
1 answer

how to generate lazy iteration thing in typescript

currently I am still doing this question : Make a general purpose infinite sequence initialisation function that creates infinite lazy sequences. It will take as parameter a function to compute the next value from the current value. In other…
1
vote
2 answers

How to create lazy combinations

My question is very simple, how do I make this code lazy: /* input: [ [1, 2], [3, 4], [5, 6] ] output: [ [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6], ] */ func…
Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75
1
vote
1 answer

using Generic sequences system in common lisp with an alist from jonathan

I'm working with the messenger api from facebook, using ningle. there is a moment in my program that I need to work with this alist coming from jonathan: CL-USER> (defparameter *params* '(("entry" (("messaging" …
anquegi
  • 11,125
  • 4
  • 51
  • 67
1
vote
1 answer

Why is this lazy-sequence not printing?

I cannot figure out why this lazy-sequence is not printing. I've looked at other posts on here (such as this) and none seem to be exactly what I am looking for. Here is the code segment... (defn exp [x n] (reduce * (repeat n x)) ) (defn primes …
1
vote
2 answers

Lazy list of x, f x, f (f x),

Batteries.LazyList allows one to define lazy lists. I would like to define a lazy list consisting of x, f x, f (f x), f (f (f x)), etc. Based on comments in the module documentation, it appears that from_loop is the function I want: "from_loop…
Mars
  • 8,689
  • 2
  • 42
  • 70
1
vote
1 answer

merging 2 lazy lists type conflict

Why my merge function complains about its type ? Isn't my x a type 'a seq ? type 'a seq = Stop | Cons of 'a * (unit -> 'a seq) let rec linear start step= (*builds a seq starting with 'start'*) Cons (start, fun () -> linear (start+step)…
Oleg
  • 1,479
  • 3
  • 21
  • 42
1
vote
2 answers

Perform "get" on all HashMap elements of a LazySeq

I'm parsing some XML data from Stack Exchange using clojure.data.xml, for example if I parse Votes data it returns a LazySeq containing a HashMap for each row of data. What I am trying to do is to get the values associated with only certain keys,…
Phrancis
  • 2,222
  • 2
  • 27
  • 40
1
vote
1 answer

Generate first 10 Fibonacci numbers using infinite stream

I am trying to obtain the first 10 Fibonacci numbers as follows: (take 10 (fn fibgen [a b] (cons a (fibgen b (+ a b))) 0 1)) The idea is that fibgen creates a lazy sequence (an infinite stream). Unfortunately this gives the following…
user2609980
  • 10,264
  • 15
  • 74
  • 143
1
vote
2 answers

Nested map statements in Clojure don't evaluate properly, seems related to LazySeq

I have written a function in Clojure that is supposed to take a logical expression and return an equivalent expression where all not statements act directly on variables, like so: (not (and p q r)) becomes (or (not p) (not q) (not r)) It uses De…
Henrik
  • 423
  • 4
  • 11
1
vote
1 answer

Lazy seqs not deferring computation

I am currently going through the book Clojure for the Brave and True, in an attempt to learn the language, but I'm a bit hung up on lazy seqs, and I'm afraid the book does a poor job explaining them. But, according to the book, something like this:…
iCodeSometime
  • 1,444
  • 15
  • 30