Re: Let usage question

2010-10-28 Thread Chouser
On Wed, Oct 20, 2010 at 3:21 PM, Rich Hickey richhic...@gmail.com wrote: On Oct 20, 1:34 pm, cej38 junkerme...@gmail.com wrote: This question leads into something that I read in Joy of Clojure (page 161 in the latest MEAP edition): If you manage to hold onto the head of a sequence somewhere

Re: Let usage question

2010-10-20 Thread Tom Faulhaber
Dave, Yes, this is perfectly idiomatic and many people in Clojure (and also Haskell, for example) use let to help document how they're building up their computation. Stuart's suggestion is also good and it's largely a matter of personal preference which to use when. Of course, as you use

Re: Let usage question

2010-10-20 Thread Alan
I agree with Tom (and with Stuart). I tend to like using - when it's convenient, since all you're really doing is performing a list of transformations on a single object. However, the let is better documentation if that's ever going to matter. Not because it makes it easier to understand what

Re: Let usage question

2010-10-20 Thread lprefontaine
Hi, readability might be a concern but it's not the only criteria. a) Do you need to trace intermediate results ? Then you need a binding so you do not redo the work twice (presumably, I exclude memoized functions here). Of course if the code has some side effects, the choice is

Re: Let usage question

2010-10-20 Thread Alan
By the way, http://tinyurl.com/2a235cn is an example of your style of let being used in the Clojure source: the definition of defn itself. It's a little overdone and weird-looking, but the alternative of deeply nested forms would be much worse. I didn't notice your question about technical

Re: Let usage question

2010-10-20 Thread cej38
This question leads into something that I read in Joy of Clojure (page 161 in the latest MEAP edition): If you manage to hold onto the head of a sequence somewhere within a function, then that sequence will be prevented from being garbage collected. The simplest way to retain the head of sequence

Re: Let usage question

2010-10-20 Thread Alan
When you work with a lazy sequence, Clojure (java really) automatically garbage-collects elements you're done with. It can only be certain you're done with them if you no longer have any reference to them, direct or indirect. If you've bound the head of the sequence to a local, then you can still

Re: Let usage question

2010-10-20 Thread Dave Ray
Not only did my question get answered, but I learned several new things in the process. Thanks! Dave On Wed, Oct 20, 2010 at 1:52 PM, Alan a...@malloys.org wrote: When you work with a lazy sequence, Clojure (java really) automatically garbage-collects elements you're done with. It can only

Re: Let usage question

2010-10-20 Thread Rich Hickey
On Oct 20, 1:34 pm, cej38 junkerme...@gmail.com wrote: This question leads into something that I read in Joy of Clojure (page 161 in the latest MEAP edition): If you manage to hold onto the head of a sequence somewhere within a function, then that sequence will be prevented from being

Re: Let usage question

2010-10-20 Thread cej38
great! good to know On Oct 20, 3:21 pm, Rich Hickey richhic...@gmail.com wrote: On Oct 20, 1:34 pm, cej38 junkerme...@gmail.com wrote: This question leads into something that I read in Joy of Clojure (page 161 in the latest MEAP edition): If you manage to hold onto the head of a

Re: Let usage question

2010-10-20 Thread Michael Ossareh
On Wed, Oct 20, 2010 at 09:52, Alan a...@malloys.org wrote: I agree with Tom (and with Stuart). I tend to like using - when it's convenient, since all you're really doing is performing a list of transformations on a single object. However, the let is better documentation if that's ever going

Let usage question

2010-10-19 Thread Dave Ray
Hey, I'm parsing a file with a chain of filter and map operations. To make it a little more readable (to me), I put the steps in a let like this: (defn parse-dictionary [reader] (let [lines(read-lines reader) trimmed (map #(.trim %1) lines) filtered (filter