Two things at play here:

1- concat is defined to have 4 different arities: 0-arg, 1-arg, 2-arg, 3+args. 
In order to figure out which arity to use, apply has to realize at least as 
many elements as the minimum number of args required by the largest arity, 
which in this case is 3
2- apply has a small bug that causes it to realize one element more than 
necessary, in this case making it realize 4 elements rather than 3, here's a 
ticket with a patch fixing that issue: 
http://dev.clojure.org/jira/browse/CLJ-1583

Nicola

> On 2 Jun 2016, at 19:26, Andy L <core.as...@gmail.com> wrote:
> 
> Hi,
> 
> I have a riddle I am not sure how to solve:
> ```
> user=> (defn just-a-demo-seq[] (println "in just-a-demo-seq") [1 2 3 4 5 6 7 
> 8 9])
> #'user/just-a-demo-seq
> user=> (def do-not-print-it (apply concat (repeatedly just-a-demo-seq)))
> in just-a-demo-seq
> in just-a-demo-seq
> in just-a-demo-seq
> in just-a-demo-seq
> #'user/do-not-print-it
> ```
> 
> Question is why `just-a-demo-seq` is invoked 4 times.
> 
> We spent some time trying to answer the question to the point of analyzing 
> RT.java and core.clj and pretty much ruled out `concat`. It seems that 
> `apply` os somewhat greedy exercising too many elements of the lazy sequence.
> 
> Any insight?
> 
> Thanks,
> Andy
> 
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to