One common case also, is if you want to store in a datastructure not the
current function of a global var, but rather the var itself, so that
everytime you want to use it, you'll get the current value bound to the var,
and not the value bound that happened to be bound to the var when at the
point in time it was stored in the datastructure.

By example:

(defn toupper [s] (.toLowerCase s))
#'user/toupper
(def str-funs {:to-upper toupper})
#'user/str-funs
((:to-upper str-funs) "Foo")
"foo"
; arg, let's change toupper definition (e.g. the root value associated to
the toupper var)
(defn toupper [s] (.toUpperCase s))
#'user/toupper
; now let's call the to-upper function ...
((:to-upper str-funs) "Foo")
"foo"
; arg, still the old definition. Oh wait ! In the str-fun defs, toupper has
been evaluated to its root value, and I've stored a function in the
datastructure
; let's store the toupper var itself
; let's retry all this again, to be sure
(defn toupper [s] (.toLowerCase s))
#'user/toupper
(def str-funs {:to-upper #'toupper}) ; or (var toupper), if you don't like
the #' reader macro
#'user/str-funs
((:to-upper str-funs) "Foo")
"foo"
; ok so now let's redefine toupper
(defn toupper [s] (.toUpperCase s))
#'user/toupper
((:to-upper str-funs) "Foo")
"FOO"
; Yay !




2011/1/13 rob levy <r.p.l...@gmail.com>

> One common use is for referring to private functions in other namespaces.
>  For example, say you want to write tests for foo.core/p, a privately
> defined function.  It is private in terms of your intent as expressed in
> your API, but you can still access the var from foo.core-test and call the
> function in your tests as #'foo.core/p.
>
>
> On Wed, Jan 12, 2011 at 10:29 PM, gaz jones <gareth.e.jo...@gmail.com>wrote:
>
>> its a reader macro equivalent to the var special form:
>>
>> (var symbol)
>> The symbol must resolve to a var, and the Var object itself (not its
>> value) is returned. The reader macro #'x expands to (var x).
>>
>> from:
>>
>> http://clojure.org/special_forms#var
>>
>> On Wed, Jan 12, 2011 at 9:11 PM, Alex Baranosky
>> <alexander.barano...@gmail.com> wrote:
>> > Hi,  I find it extremely hard to google this to learn more!  I'd like to
>> > know some good sources of further information on when to use #' .  It is
>> a
>> > bit mysterious to me at this point.
>> >
>> > --
>> > 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<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<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