Thanks for the pointers. I was indeed able to make it work with
dorun. ;)

Still, I'm not sure I understand what all the fuss is about regarding
laziness. I'll take your word for it for now but I hope to grock it
eventually.

Thanks!

Max


On Mar 2, 12:30 am, David Nolen <dnolen.li...@gmail.com> wrote:
> Remember that you can force lazy sequences if you need to as you are with
> doseq with doall (retains head) and dorun (does not) as well.
> You probably want
>
> (dorun (map #(add-watch % watcher callback-fn) all-agents))
>
> I think it's pretty clear here what's going on.  Your code needs
> side-effects. In Clojure side-effect code tends to stands out.
>
> I sympathize with your frustration, I remember getting excited about Lisp
> macros but spending many many long hours trying to understand how to write
> even a simple one.
>
> Similarly I think lazy sequences are worth the initial frustration ;)
>
> On Mon, Mar 2, 2009 at 12:06 AM, max3000 <maxime.lar...@gmail.com> wrote:
>
> > Hi,
>
> > I find the laziness in clojure very hard to wrap my head around. I
> > understand the idea and it's probably nice in theory. However, in real
> > life it doesn't seem really useful beyond hardcore mathematical
> > problems.
>
> > Case in point, I just spent 2 hours debugging a piece of code (shown
> > below) that seemed simple enough. This is the 3rd time this week that
> > I've lost substantial time to laziness. I'm pretty pissed to tell the
> > truth and I find myself wrapping things in doseq more and more just to
> > be sure. I rarely use 'for' anymore, what's the point?
>
> > Here is the code that gave me trouble:
>
> >    (map #(add-watch % watcher callback-fn) all-agents)
>
> > This was not executing. I had to change it to the below expression:
>
> >    (doseq [agent all-labor-agents]
> >      (add-watch agent total-labor-agent callback-fn))
>
> > This second expression seems less elegant than the map above. Why
> > doesn't clojure realize that an add-watch really should actually loop
> > over all-agents? Why is it that Java calls are not made in similar
> > expressions?
>
> > Is laziness so useful that we should waste time investigating and
> > fixing errors like this? Sure, there could be special constructs for
> > laziness when we really need it. However, clojure shouldn't default to
> > it IMO. At this point, laziness is a nice concept but it feels
> > somewhat removed from reality to tell the truth. Of course I want to
> > iterate over my collection when I'm doing an add-watch!
>
> > What am I missing?
>
> > Thanks,
>
> > Max
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to