Suppose at my REPL I do...

(defn direct-report-oneplustwo [] (println (str "Direct one plus two is " 
((fn [n] (+ 1 n)) 2) ".")))

...then I presume that the compiler has compiled my 
direct-report-oneplustwo function, and that this has included compilation 
of my anonymous function (fn [n] (+ 1 n)).  So that now if I run...

(direct-report-oneplustwo)

...at my REPL it just needs to run this precompiled code to tell me my 
answer 3 - no additional compilation required.

So far so good.

But what if instead I do this at my REPL...

(defn adder-make [m] (fn [n] (+ m n)))

(defn indirect-report-oneplustwo [] (println (str "Indirect one plus two is 
" ((adder-make 1) 2) ".")))

...Now at this point, both adder-make and indirect-report-oneplustwo should 
have been compiled.  But unlike our first approach, the anonymous function 
(fn [n] (+ 1 n)) has not yet been created by (adder-make 1) and so 
presumably (??) has not yet been compiled??

I am presuming that it is only when we actually run the report function...

(indirect-report-oneplustwo)

...that (adder-make 1) is actually run, thereby producing the anonymous 
function (fn [n] (+ 1 n)), which then gets compiled right then-and-there, 
immediately followed by its execution??

But maybe this is wrong!?  Maybe instead somehow the compiler managed to 
"pre-compile" the anonymous function as part of the compilation of 
adder-make?  Maybe there is a stored compiled "template" function, the 
bytecode for which gets "rolled out" at runtime in slightly different ways 
depending on the parameter m??

Can anyone clarify for me what happens here?

Thanks,

Mark.

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

Reply via email to