if it has tighter scope, then I don't understand why you don't have an
infinite loop.  The nested my-list that you redefined should have
nothing to do with the my-list that you are doing the 'rest' check
on.  (rest my-list) should always be non-nil because the inner let is
operating on a different my-list.  That's how it looks to me, at
least.  I saw that there's a re-def function that I bet would work,
but everyone says to avoid def because of it's global scope.  hmmmmm
that must be some magic about the loop construct.  I dunno.  I'm still
confused.  Every version of the python code makes sense.  I've got
this reference to my-list, and I can change that reference.  I see the
same thing happening here, but it's scoped inside a let barrier.  I
seem to remember in clisp, there was a setq.  maybe that's what I'm
missing.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to