>>In my stupidity I chose prn as function name, which removed from the
namespace on >>reload, because clojure.core/prn „overwrites“ the Var again.
Maybe such a functionality >>could be also implemented for normal reload?
But then what happens to other >>namespaces which refer to this Var? I
admit, this is not a trivial question.

I don't think anything gets removed (unloaded), at least that's the way I
remember it.

Things get a little tricky with :reload-all.  For example (I don't have a
repl handy to verify, but this is how I remember it):

---------
original files:
---------

(ns some.ns.foo1
  "namespace foo 1"
  (:gen-class)
  (:require [some.ns.foo2 :as foo2]))

(defn func-a
  []
  (foo2/func-x "abc"))

(defn func-b
  []
  (str "123"))


(ns some.ns.foo2
  "namespace foo 2"
  (:gen-class))

(defn func-x
  [z]
  (str z))

(defn func-y
  []
  (str "456"))

---------
save and go to REPL:
---------

user=> (require '[some.ns.foo1 :as foo1])
user=> (require '[some.ns.foo2 :as foo2])
user=> (foo1/func-a)
"abc"
user=> (foo1/func-b)
"123"
user=> (foo2/func-x "def")
"def"
user=> (foo2/func-y)
"456"


---------
change files:
---------

(ns some.ns.foo1
  "namespace foo 1"
  (:gen-class)
  (:require [some.ns.foo2 :as foo2]))

(defn func-a
  []
  (foo2/func-x "abc"))


(ns some.ns.foo2
  "namespace foo 2"
  (:gen-class))

(defn func-x
  [z]
  (str z "new"))

(defn func-y
  []
  (str "456" "new"))

---------
save and go back to REPL:
---------

user=> (require '[some.ns.foo1 :as foo1] :reload-all)
user=> (foo1/func-a)
"abcnew"
user=> (foo1/func-b)
"123"
user=> (foo2/func-x "def")
"def"
user=> (foo2/func-y)
"456"


Notice, the removed function in foo1 still exists, because it was not
overwritten by anything.  Also, notice that we specified :reload-all for
foo1, which then reloads foo2 in the context of foo1, so when calling a
function in foo1 that calls foo2, we get the updated output.  But, when
calling foo2 functions directly, we get the old functions.

This could all be BS, so verify before taking my word for it, as stated I
don't have a repl to verify, but from memory it seems that this is the
behavior.

 - Mark


On Mon, Jul 19, 2010 at 4:41 PM, Meikel Brandmeyer <m...@kotka.de> wrote:

> Hi,
>
> Am 19.07.2010 um 22:20 schrieb Peter Schuller:
>
> >> I haven't tested what happens to the deftest stuff, but the „moving
> function“ could be addressed.
> >
> > Cool. I had not yet run into the moving function case with clojure (I
> > did several times with Common Lisp), so that might be a non-issue. I
> > was just presuming that no magic was going on.
>
> It turns out you shouldn't also listen to me. I think I will stop writing
> emails for today. I got caught by the last-var-wins feature.
>
> Clojure 1.2.0-master-SNAPSHOT
> user=> (require 'foo.bar)
> nil
> user=> (foo.bar/baz)
> 5
> ; Remove function baz here from file
> user=> (require :reload 'foo.bar)
> nil
> user=> (foo.bar/baz)
> 5
>
> In my stupidity I chose prn as function name, which removed from the
> namespace on reload, because clojure.core/prn „overwrites“ the Var again.
> Maybe such a functionality could be also implemented for normal reload? But
> then what happens to other namespaces which refer to this Var? I admit, this
> is not a trivial question.
>
> Sincerely
> Meikel
>
> --
> 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<clojure%2bunsubscr...@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 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