> - First, it seems from the api documentation that @x will work fine even if
> x is a var. I don't understand the following:
> Why isn't x a var?

vars automatically resolve to their value for convenience, however you
can access the var using (var x) or use the shorthand #' notation
which does the same thing:

user=> (var? #'a)
true


> - Second, I remember having seen a ref? function analogous to var? in the
> online documentation, but it doesn't seem to actualy exist:

(def r (ref 5))
user=> (isa? clojure.lang.Ref (class r))
true

Notably in this example r is actually a var, but is holding a ref as
its value.

So to write your function
(defn my-deref [x]
  (if (or (isa? clojure.lang.Ref (class x))
          (isa? clojure.lang.Agent (class x))
          (isa? clojure.lang.Atom  (class x)))
      @x
      x))

user=> (my-deref (ref 1))
1
user=> (my-deref (atom 1))
1
user=> (my-deref 1)
1
user=> (def x 2)
user=> (my-deref x)
2


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