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 following question:
but it's still not clear.
My question would be how the call determines if another call is "equal" to a cached call and how long does it stays in the cache? I tried to (source lazy-seq) but apparently it's in Java land so I'm out of luck here.
For a simple lazy-seq, taking just one argument (like say the list of powers of two), what if I call it with 5 and then 8? Are just these two values cached?
And what is the point in creating and caching an infinite list to get an infinite structure if I'm going to ruin the memory by caching every input I already called the lazy function with?
Because it says it's caching the result on every subsequent calls... With an 's'.
1: result for argument being '1' cached 2: result for argument being '2' cached 3: result for argument being '3' cached ... 230: I counted up to 230 and it's great because I'm lazy and all, but now there's a 2**30 cache in memory caching all the previous calls for all the subsequent calls.
or is it just the last call that is cached?
What if I write a lazy function taking trees as arguments? Does it run equals? on the argument passed to know if there needs to be a new evaluation?
Can this behavior somehow be traced at run-time?