On Tue, Aug 11, 2009 at 11:40 AM, John Harrop<jharrop...@gmail.com> wrote:
> On Tue, Aug 11, 2009 at 6:39 AM, Krukow <karl.kru...@gmail.com> wrote:
>>
>> I was browsing through core when I noticed something I didn't
>> understand in 'into' (from core.clj):
>>
>> ;redef into with batch support
>> (defn into
>>  "Returns a new coll consisting of to-coll with all of the items of
>>  from-coll conjoined."
>>  [to from]
>>  (if (instance? clojure.lang.IEditableCollection to)
>>    (#(loop [ret (transient to) items (seq from)]
>>        (if items
>>          (recur (conj! ret (first items)) (next items))
>>          (persistent! ret))))
>>    (#(loop [ret to items (seq from)]
>>        (if items
>>          (recur (conj ret (first items)) (next items))
>>          ret)))))
>>
>> I am wondering about the construct #(loop ...). As far as I can see
>> you might as well just use (loop). I.e.,
>>
>> (defn into2
>>  "Returns a new coll consisting of to-coll with all of the items of
>>  from-coll conjoined."
>>  [to from]
>>  (if (instance? clojure.lang.IEditableCollection to)
>>    (loop [ret (transient to) items (seq from)]
>>        (if items
>>          (recur (conj! ret (first items)) (next items))
>>          (persistent! ret)))
>>    (loop [ret to items (seq from)]
>>        (if items
>>          (recur (conj ret (first items)) (next items))
>>          ret))))
>>
>> I suspect that I am missing some point. Could someone clarify?
>
> I don't know. Perhaps at this point during bootstrap loop doesn't create
> recur points and so the anonymous lambdas are necessary? But then recur
> would rebind the (nonexistent) lambda parameters I'd have thought.

I don't know either.  'loop' is a macro that expands to
'loop*', which is in turn a special form.  At that most
basic level, loop* still creates a recur point, so I don't
think that's the point.

I wonder if it has to do with clearing locals for tail
calls or perhaps avoiding holding the head of 'from'.

--Chouser

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