On Oct 9, 8:35 am, mb <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On 9 Okt., 08:39, Krukow <[EMAIL PROTECTED]> wrote:
>
> > (str x " loves " y))
>
> > Now the question is why is it logging 5 times? Is this a bug, or has
> > something fundamental changed? I checked out Clojure from SVN a few
> > days ago.
>
> Have a look at the implementation of str in boot.clj:
> ...
> ([x & ys]
> (loop [sb (new StringBuilder #^String (str x)) more ys]
> (if more
> (recur (. sb (append (str (first more)))) (rest more))
> (str sb))))
> ...
>
> First logging to get there.
> Second logging in the second line: (str x)
> Third logging in 4th line: (str (first more)) ; (first more) == "
> loves "
> Fourth logging in 4th line: (str (first more)) ; (first more) == y
> Fifth logging in 5th line: (str sb)
>
Which still leaves the question - what has changed?
The answer is, self-calls such as that in str used to be compiled into
direct invocations of the same function object, rather than going
through the var. Currently they go through the var. I've yet to
profile the performance difference, but the liability of direct self
call is that a long running function that called itself couldn't be
updated/fixed, since it would never re-read the new code. That said,
in practice such long-running self callers usually end up being agents
whose recursive action sends take the form of #'vars, ensuring the use
of new definitions.
The way it currently works makes the long-running case thought-free,
but if there ends up being a big perf difference I may switch it back
and document the techniques to use for the long-running case, since it
is certainly the minority.
In any case, the example output on the site is currently mismatched
with the behavior and I'll have to come up with a better one.
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---