On Monday, June 2, 2014 3:32:59 PM UTC-5, Lee wrote:
>
> I've generally liked Clojure's pervasive laziness. It's cute and it
> sometimes permits lovely, elegant approaches to particular programming
> problems.
>
After worrying about some bad potential problems with mutation of data
structures (well all have to side-effect sometimes) that require some care
with laziness--and not just my newbie "oh darn I forgot that line was lazy"
problems--I had also come to feel that laziness wasn't worth its benefits.
Cute, yeah, but the fact that I can do (take n (generate-infinite-seq)) rather
than(generate-finite-seq n) is not helpful, and if I don't need to keep the
whole thing in memory, then I can write a loop that doesn't. But so much
of what's convenient about Clojure is lazy, so it's a hard thing to avoid.
I've begun to see that laziness can really provide a modularity benefit.
My main project is an application that generates subsequent states of a
simulation using iterate, which generates a lazy sequence. I can do
things like this:
(nth
(map write-summary-data-about-each-state-to-file
(map display-some-data-for-debugging-about-each-state
(generate-infinite-sequence-of-states initial-state)))
index-of-last-state-I-care-about)
I typically don't need all information about every subsequent state; I just
need to know a few things, and that's what those functions that are mapped
do. The important point is that those functions I'm mapping over the
sequence of states are optional. I need different ones in different
situations. In the first, Common Lisp version of this application, I
embedded call to every such function into my main loop, and wrapped each
one in an if test on a separate Boolean variable. So I had to embed every
call that I might possibly want to use into the main loop. Now my main
"loop", i.e. the function that iterate calls, is only a few lines long, and
I can add arbitrary reporting functions whenever I want using map. None of
that is a solution to the problems that laziness brings, but I now think
it's possible that it's worth dealing with laziness's drawbacks.
--
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.