Thanks,
Stu
This discussion:
http://groups.google.com/group/clojure/browse_thread/thread/534dd074f18851ab
suggests that reference types implementing IFn isn't the intended
behavior.
Using deref or @ works with all reference types:
user> (defn my-fn [x] (+ x 3))
#'user/my-fn
user> (def my-agent (agent my-fn))
#'user/my-agent
user> (@my-agent 4)
7
--Steve
Minor technicality ... Vars are a reference type, but deref and @
don't work with them.
--
R. Mark Volkmann
Object Computing, Inc.
> Minor technicality ... Vars are a reference type, but deref and @
> don't work with them.
I'm guessing you're thinking of an interaction like this:
user=> (def a 3)
#'user/a
user=> @a
java.lang.ClassCastException: java.lang.Integer cannot be cast to
clojure.lang.IDeref (NO_SOURCE_FILE:0)
user=>
However, it's important to remember that the expression "a" does not
evaluate to the Var named "a". The Var named by "a" can be accessed
via (var a) or #'a.
deref does work with Vars:
user=> @(var a)
3
user=> @#'a
3
user=>
deref works with objects that implement clojure.lang.IDeref and
clojure.lang.Var is among them:
user=> (isa? clojure.lang.Var clojure.lang.IDeref)
true
user=>
--Steve
Yes, that's what I was thinking about.
> However, it's important to remember that the expression "a" does not
> evaluate to the Var named "a". The Var named by "a" can be accessed via (var
> a) or #'a.
>
> deref does work with Vars:
>
> user=> @(var a)
> 3
> user=> @#'a
> 3
> user=>
>
> deref works with objects that implement clojure.lang.IDeref and
> clojure.lang.Var is among them:
>
> user=> (isa? clojure.lang.Var clojure.lang.IDeref)
> true
> user=>
Thanks for clarifying that!