a pre-condition attached to your fn would be a nice and clean way to
check for upper/lower case without 'polluting' the fn itself with if
statements...just a thought ... :-)
Jim
On 22/10/12 16:16, Jim foo.bar wrote:
A couple of issues:
1) 'name' is a fn in core so it's almost never a good idea to shadow
it like this...
2) also it is not a good idea for a fn to start with 'def' unless it
actually defines a top-level form inside it like in macros
3)If you need all your keys in capital I think it would be faster to
just capitalise them without checking...not sure though...
Jim
On 22/10/12 16:09, Bronsa wrote:
I've had this happening to me too.
Couldn't figure out wtf was going on.
Until somebody understands what's the problem is, you can(let [s
(.sym ^clojure.lang.Keyword k)] ..) and call name on s
2012/10/22 JvJ <kfjwhee...@gmail.com <mailto:kfjwhee...@gmail.com>>
I'm getting a REALLY weird error. I'm trying to check if a set
of keywords are all uppercase.
When binding a value to 'res' in the let statement, I traverse a
list of keywords. However, the calls to the name function on those
keywords give nil. The debug print statement clearly shows that
the class of k is a keyword, and yet its name is nil?
I really don't get it.
;; Program
(defn defrel-fn
"Adds a relation definition to the *relations* map."
[name keys]
(let [res (every? (fn [k]
(println "k: " (name k) ", " (class k)) ;;
Added for debugging
(= (name k) (.toUpperCase (name k)))) keys)
;; keys need to be all in uppercase letters!
;;_ (when-not res (throw (Exception. "Error. All keys
must be upper-case.")))
kns (apply hash-map (mapcat vector keys (range))) ;;
represents a map of keys to indices
]
(swap! *relations*
assoc name {:fields kns
:unfields (vec keys) ;; A map of indices
to keys is best represented as a vector
})))
;; Output from repl
=> (worldrep.core/defrel-fn 'mother [:SELF :CHILD])
k: nil , clojure.lang.Keyword
NullPointerException
clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:314)
--
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
<mailto: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
<mailto: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
--
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