Normal function is faster than the function which has inner function
which actually doesn't run.
------------------------------------------------------------------------------
(defn aaa1 []
(defn bbb [] 1)
1)
(defn aaa2 [] 1)
user> (time (dotimes [_ 10000000] (aaa1)))
"Elapsed time: 4083.291 msecs"
nil
user> (time (dotimes [_ 10000000] (aaa2)))
"Elapsed time: 58.34 msecs"
nil
------------------------------------------------------------------------------
In scheme's case both code have been excuted in the same time.
None of clojure code I have seen have inner function.
I like inner function because it doesn't consume a name from namespace
and make it clear that inner function is only used by outer function.
Thanks.
Bill Smith
Austin, TX
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
letfn is pretty good.
---------------------------------------------------------------------------
(defn aaa1 []
(letfn [(bbb [] 1)]
1))
user> (time (dotimes [_ 10000000] (aaa1)))
"Elapsed time: 100.981 msecs"
nil
---------------------------------------------------------------------------
Hi Kevin.
I have understood that def is not lexical scoped.
---------------------------------------------------------------------------
(defn aaa1 []
(defn bbb [] 1)
1)
user> (aaa)
1
user> bbb
#<user$aaa1__2324$bbb__2326 user$aaa1__2324$bbb__2326@55eef3c1>
---------------------------------------------------------------------------
Thank you!