I would like to have a function which tells me about the values of a
var, where the parameter to the function is a string equal to the
'name' of the var.

For example:

(defn checkNil [name]
     "If the var with the given (String) name is nil, display a
message; result = value of var".
     (when (nil? (value of the var called name))
        (display (str name " is nil")))
     (value of the var called name))

so that

(def x nil)
(checkNil "x")

should display: "x is nil" -- (display s) being a function that shows
the string s somewhere.

The question is, how do I express (value of the var called name)?

I tried this: (var (symbol name))
but that caused the exception: clojure.lang.PersistentList cannot be
cast to clojure.lang.Symbol

Is this possible?

----------------
Another way to do it would be as follows.

(defn checkNil [x]
     "If the variable x is nil, display a message; result = value of
x."
     (when (nil? x)
        (display (str (name of the var x) ) " is nil")))
       x)

so that

(def x nil)
(checkNil x)

should display: "x is nil".

In this case - how to do: (name of the var x)?
--~--~---------~--~----~------------~-------~--~----~
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