You can also do stuff in the middle of a let;

(let [a vala
      b valb
      _ (do-something-with a b)
      c (some-fn a b)
      d (some-fn a b)
      _ (do-something a b c d)
      e (fn ...)
      f (fn ....)]
  (and-whatever-else))

Here _ is just some arbitrary unused variable.

Note that you can also reuse existing variables which sometimes make
things clearer;

(let [a (some...)
       a (if something x y)]
   (some... a))

-Rgds, Adrian.

On Fri, Feb 26, 2010 at 2:28 AM, kuniklo <milese...@gmail.com> wrote:
> One of my least favorite things about common lisp was the degree of
> nesting it required for sequential variable definitions. For common
> code like this:
>
> (let (a vala)
>     (b valb)
>     ... do something with a & b...
>     (let (c (fn a b))
>           (d (fn a b))
>     ... do something with a, b, c, d...
>           (let (e (fn ...))
>                (f (fn ....))
>
> etc. You eventually get a very deeply nested function simply because
> the values of variables assigned later in the code depend on values
> determined earlier in the code. From what I can this is also the case
> in clojure, correct?
>
> In contrast, the python/ruby/java approach (which I realize has its
> own warts).
> a = 1
> b = 2
> c = a * b
> d = a + c
> e = func(d)
>
> in which new bindings are automatically created in the current scope,
> tends to be more readable in many cases.
>
> I'm new to clojure so I'm wondering - are there idiomatic ways of
> reducing the degree of scope-nesting let incurs or do people just tend
> to try to avoid that kind of code with smaller sub functions etc?
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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