On Thu, Jun 11, 2009 at 5:06 AM, rb <raphi...@gmail.com> wrote:

>
> HI,
>
> in his post "Macro design, by example" [1], Meikel Brandmeyer
> mentioned that it is possible to reload a function (in contrast to a
> macro) in a running application:
>
> "Now all you have to do is to just reload the single function in the
> running application. This can be easily done by environments like
> SLIME or VimClojure. Et voila. The next time the function is called
> you already get the benefit. Without recompilation of the whole app...
> "
>
> Is achieving this a general possibility for any app, or are there
> limitations to updating running applications?
> For example, is it necessary to start the app in a REPL to be able to
> update it while it's running? Or is it possible to open a REPL
> attached to a running application?
>

Clojure loads code only when you tell it to via require, use, and load (or
their equivalents in an ns definition), so you do need a way to tell it to
reload. Currently that could happen via a REPL or Slime or any other I/O
mechanism you could build into your app to take input and load code. It's
pretty easy to launch an app and a REPL using the built-in command line
arguments of clojure.main: java -cp clojure.jar --init myapp.clj --repl.
Opening a slime connection in your init script is also pretty easy.


> I'm very curious about this (possibly compared to Erlang's hot code
> update possibilities) and would appreciate any pointer or example.
>
> Thanks!
>
> Raphael


A big difference with Erlang's hot code loading is that in Erlang the
runtime tracks multiple versions of code by module, and there's a well
defined way for your code to indicate whether it always wants the latest
version of a function it calls or whether only new Erlang processes see the
new code. With Clojure it's more granular and forceful. As soon as a given
function is loaded, the new version is visible globally to the program
(except where a particular thread may have purposely set up a thread-local
binding in its current context). If you're updating multiple functions with
changes in their signatures or meaning, you have to be very careful. There
was an interesting query on the group [1] about the possibility of
supporting multiple versions of scripts by using dynamic classloaders, but
it didn't generate discussion.

Shawn

[1]
http://groups.google.com/group/clojure/browse_thread/thread/e05f73854549a25d/7c22e8472ff738a4

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

Reply via email to