On Tuesday, April 8, 2014 7:57:10 AM UTC-5, sorin cristea wrote:
>
>
> What exactly you mean by '*The point was you aren't using lazy-seq as
> intended here since you are always creating a singleton sequence*' ? In
> my sum function...I intend to compute sum of elements of a collection.
>
L
Hi Webb,
What exactly you mean by '*The point was you aren't using lazy-seq as
intended here since you are always creating a singleton sequence*' ? In my
sum function:
(
defn test-fc
"sum of all collection elements using recursion and laziness"
[coll]
(letfn [(sum-fc [sum coll]
Hi James,
I'm new to clojure and maybe for this reason it's possible to put some
'stupid' questions, I came for Java so for me it's normal when I call a
fc/method to execute the body of that fc/method and return a result; this
is the reason for why I expect a result when I call (test-fc (ran
The point was you aren't using lazy-seq as intended here since you are
always creating a singleton sequence. What's going on behind the scenes
here is in effect just trampolining thunks.
(defn thunked-sum [sum coll]
(if-let [[x & more] (seq coll)]
(fn [] (thunked-sum (+ sum x) more))
Why do you expect (test-fc (range 210432423543654675765876879)) to return a
result?
Even if each iteration of the loop takes only 1 nanosecond, your function
would take 6 billion years to complete.
- James
On 7 April 2014 21:01, sorin cristea wrote:
>
> Hi Gianluca,
>
> I have a question ; w
Hi Gianluca,
I have a question ; why when a run/execute command/code line (test-fc
(range 210432423543654675765876879)) it's not executed the function test-fc
and return the sum for all 210432423543654675765876879 elements? why should
I put the test-fc reference to a variable, x, like you pr
Hi Ginaluca,
I have a question ; why when a run/execute command/code line (test-fc
(range 210432423543654675765876879)) it's not executed the function test-fc
and return the sum for all 210432423543654675765876879 elements? why should
I put the test-fc reference to a variable, x, like you p
Hi sorin,
your function computes a sequence of just one element (the sum of the
collection members), so I would say it is not a typical use of (lazy) seqs
to see that the code is indeed lazy, you can try:
(def x (test-fc (range 210432423543654675765876879)))
and see that it returns immediately
First have a look at delay (and clojure.lang.Delay) and try to understand
it. LazySeq is just a delay with a fancy interface (supporting seq, first
and rest). There is no recursion per se in the LazySeq object. What makes
it harder to understand is the idiom of using lazy-seq together with cons
and
Hi,
maybe this question was already put it here, but can someone explain how
exactly work internal a function wrapped with lazy-seq keyword. For example
in the below code sample:
(
defn test-fc
"sum of all collection elements using recursion and laziness"
[coll]
(letfn [(sum-fc [sum
10 matches
Mail list logo