oh. I missed the "recur my-list" in your answer. So we still don't have an iterative solution. Recursion should never be necessary. I agree that it simplifies things sometimes and you can use it when you are stuck. . . . .but no need to push a whole stack frame for such a simple problem, I would posit.
On Jan 11, 1:41 pm, James Reeves <weavejes...@googlemail.com> wrote: > On Jan 11, 6:19 pm, e <evier...@gmail.com> wrote: > > > This gets to my question perfectly. Why is your code "my-list > > (rest (rest my-list)) " legal? > > Because you're not actually changing anything. > > In theory, the let form can be derived from anonymous functions. So > (let [x y] ...) is the same as ((fn [x] ...) y). > > Or, to give you a more practical example: > > (defn f [x] > (let [x (+ x 1)] > (* 2 x))) > > Is the same as the following Python code: > > def f(x): > def g(x): > return x * 2 > return g(x + 1) > > We're not changing the value of x, we're just rebinding it within the > scope of the function. The value of x in g is not the same as the > value of x in f. > > In practice, let forms are never actually implemented as nested > functions, because that would be far too slow. But in theory, nested > functions are equivalent to let forms. > > > seems like: > > [my-list (for [x some-list] [x])] > > > is simpler to understand than: > > [my-list (vec (map vector some-list))] > > It probably is :) - I just haven't had the opportunity to use the for > macro yet. > > - James --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---