On Tue, Oct 23, 2012 at 2:58 PM, Jim - FooBar(); <[email protected]>wrote:
> On 23/10/12 19:57, Brian Hurt wrote:
>
>> Unless you don't need to do it at all.
>>
>
> niiiice... ;-)
>
>
I was actually serious. One of the advantages of lazy eval is that it lets
you delay deciding whether or not to do a computation until you actually
need the result- if there is a decent chance you won't, then it's a win.
So it lets you play games like:
(let [ lst (map expensive_function (range 1000000000)) ]
; Note, lst is lazily evaluated, the above expression is O(1) cost!
...
; Later- nah, I've changed my mind, I only need the first 10 elements
(take 10 lst)
Note that we haven't paid the cost of evaluating all billion calls to
expensive_function, we've only paid the cost of doing it 10 times- skipping
the remaining 999,999,990 calls.
Brian
>
> Jim
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscribe@**googlegroups.com<clojure%[email protected]>
> For more options, visit this group at
> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en