because of this lexical shadowing self calls to fns defined with defn
do not incur the overhead of var dereferencing, I assume this is the
reason it was added.
the lexical shadowing also breaks memoization if you create the
memoized functions via (alter-var-root #'foo memoize) and several
macros here and there emit code in this style, since reusing defn is
the easiest way to get all the good juicy metadata bits like arglists,
etc.
1.3 has changes to eliminate some of the cost of going through the var.
has the cost been lowered enough to remove the lexical shadowing in
the expansion of defn?
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
> currently (defn foo [x] (foo x)) expands to something like (def foo
> (fn foo [x] (foo x))) so the fn is bound to foo lexically in the scope
> of the fn body.
>
> because of this lexical shadowing self calls to fns defined with defn
> do not incur the overhead of var dereferencing, I assume this is the
> reason it was added.
>
> the lexical shadowing also breaks memoization if you create the
> memoized functions via (alter-var-root #'foo memoize) and several
> macros here and there emit code in this style, since reusing defn is
> the easiest way to get all the good juicy metadata bits like arglists,
> etc.
>
> 1.3 has changes to eliminate some of the cost of going through the
> var.
>
> has the cost been lowered enough to remove the lexical shadowing in
> the expansion of defn?
>
Probably, although some comparative testing of that would be nice.
Rich
https://gist.github.com/1013008
results in
$ java -jar clojure.jar ~/src/lexicaltest.clj
lexical binding run 0
"Elapsed time: 86.739 msecs"
lexical binding run 1
"Elapsed time: 8.062 msecs"
lexical binding run 2
"Elapsed time: 16.182 msecs"
var binding run 0
"Elapsed time: 61.136 msecs"
var binding run 1
"Elapsed time: 40.317 msecs"
var binding run 2
"Elapsed time: 11.641 msecs"
$
looks like going through the var takes a little more to inline?
> --
> You received this message because you are subscribed to the Google Groups
> "Clojure Dev" group.
> To post to this group, send email to cloju...@googlegroups.com.
> To unsubscribe from this group, send email to
> clojure-dev...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/clojure-dev?hl=en.