Hi Anand, You don't normally need to dereference vars because the compiler does it for you.
user> (def x 5) #'user/x This creates a var bound to the symbol "x". But now, whenever you type "x" the compiler will automatically look up the var and return its value. user> x 5 So when you type (var? x) it's resolved to (var? 5). You're asking "is 5 a var?" and the answer is no. If you want to get at the var object itself, you can use the special form (var x) user> (var x) #'user/x Note the #' prefix -- that means you're looking at a var object and not the symbol "user/x". user> (var? (var x)) true user> (var-get (var x)) 5 I think deref worked on vars in early versions of Clojure, but it doesn't now. If you're just getting started with Clojure, you can probably ignore vars. You will rarely have any need to work with vars directly unless you're doing some complicated metaprogramming. -Stuart Sierra On Jan 18, 5:11 am, "anand.prabhakar.patil" <anand.prabhakar.pa...@gmail.com> wrote: > Hi all, > I'm new to Java, Lisp and Clojure, so please be patient. I'm trying to make > a function that behaves as follows: (my-deref x) returns x if x is a var, or > @x if x is a ref. However none of the obvious options seem to be working. > > - First, it seems from the api documentation that @x will work fine even if > x is a var. I don't understand the following: > > user=> (def x 5) > #'user/x > user=> @x > java.lang.IncompatibleClassChangeError (NO_SOURCE_FILE:0) > user=> (var? x) > false > > or > > user=> (def x) > #'user/x > user=> (var? x) > false > > Why isn't x a var? > > - Second, I remember having seen a ref? function analogous to var? in the > online documentation, but it doesn't seem to actualy exist: > > user=> (ref? x) > java.lang.Exception: Unable to resolve symbol: ref? in this context > (NO_SOURCE_FILE:13) > > Thanks in advance, > Anand --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---