Tagged Questions
2
votes
1answer
47 views
Different results when a function is evaluated in the REPL than in a program
I have a feeling the answer to my question is something to do with Clojure's lazy evaluation (which I am still fuzzy on...)
So I have a function:
(defn fix-str-old [string]
(let [words (->> ...
4
votes
2answers
106 views
Building a lazy sequence out of IO data
I'm trying to get a grip on Clojure. As an exercise, I set out to build a function that returns a lazy sequence of a given subreddit's entries.
In order to make my aim clear, I put together the ...
6
votes
3answers
166 views
clojure lazy sequences in math.combinatorics results in OutOfMemory (OOM) Error
the documentation of math.combinatorics states that all functions return lazy sequences.
However if I try to run subsets with a lot of data
(last (combinatorics/subsets (range 20)))
...
1
vote
3answers
73 views
Consume http requests lazy
I'm trying to enrich data and the interface I have available for this is a web form.
Due to the very poorly quality of the data on the remote end, I run through a chain of different searches until I ...
3
votes
2answers
201 views
how to generate a series representing the binary expansion of 'e'
I'm trying to find the first 100,000 binary digits in the expansion of 'e'. Is there an algorithm to generate the binary digits of 'e' as a infinite list?
1
vote
2answers
122 views
Lazy Pascal's Triangle in Clojure
I'm trying to write a succinct, lazy Pascal's Triangle in Clojure, rotated such that the rows/columns follow the diagonals of the triangle. That is, I want to produce the following lazy-seq of ...
6
votes
1answer
91 views
laziness does not work as expected
(defn seq-trial
[]
(map #(do (println "hello " %) (inc %)) (range 10)))
(take 3 (seq-trial))
The code snippt above when evaluated prints out the following -
(hello 0
hello 1
hello 2
hello ...
2
votes
2answers
51 views
How should I make a string from a lazy sequence in clojure?
I use str to construct strings all the time:
user> (str '(1 2 3) " == " '(1 2 3))
"(1 2 3) == (1 2 3)"
and roughly once a day I get bitten on the ass by:
user> (str '(1 2 3) " == " (map ...
2
votes
2answers
164 views
Clojure infinite lazy sequences, out of bounds
I've only recently started learning Clojure, so apologies if this is a little elementary:
Can somebody please explain to me the difference between:
=> (def a (lazy-cat
[0]
...
0
votes
1answer
80 views
When I try to modify this record, why do I get an error that says it's a lazy sequence?
Here's the code that I'm working with, where I create records and then try to modify them:
(defrecord Record [Name Age Index ClassIndex])
(defn read-csv [fname count]
(with-open [file (io/reader ...
6
votes
1answer
173 views
Operations on Clojure collections
I am quite new to Clojure, although I am familiar with functional languages, mainly Scala.
I am trying to figure out what is the idiomatic way to operate on collections in Clojure. I am particularly ...
3
votes
1answer
175 views
Recursive lazy seq in Clojure
I can't understand why this lazy-seq causes a stackoverflow, and why not when you pass the sequence to dorun:
(defn very-lazy [s]
(lazy-seq
(if (seq s)
[(first s) (very-lazy (rest s))]
...
2
votes
2answers
172 views
Step-by-step example of a lazy-seq
I've got a very hard time understanding of lazyness work and how the cache is working.
I think that a step-by-step example of a lazy-seq at work could really help here. For example I've read the ...
7
votes
1answer
119 views
Understanding the execution of a lazy fibonacci implementation in Clojure
I'm trying to understand the execution of the following code:
(def fibs
(concat (lazy-seq [0 1]) (lazy-seq (map + fibs (rest fibs)))))
This is what I would expect the execution to look like
[0 ...
2
votes
1answer
192 views
Clojure flatten and laziness
Not sure what is the behaviour I observe while using flatten when constructing a lazy sequence.
Looking at the source in clojure.core I can see that the flatten function makes a call to filter and ...