I have this variable, hand, that works just fine when I define it on its own.
(def yourHand
(map
;;fn
#(let [x %]
(cond
;;hearts
(< x 10) (* x -1)
(< x 13) -10
;;diamonds
(< x 23) (* (mod x 13) -1)
(< x 26) -10
;;clubs
(< x 36) (mod x 13)
(< x 39) 10
;;spades
(< x 49) (mod x 13)
(< x 52) 10
))
;;list
(take (rand-int 12) (repeatedly #(+ 1 (rand-int 52))))))
I would like to use this variable in this function here. This works just fine when I define the variable first then just use its name in the function.
(reduce + (vec (map #(let [x %]
(cond
(= x 1) 1
:else 0
))
yourHand)))
The issue arrises when I try to define the variable within the function, like this.
(reduce + (vec (map #(let [x %]
(cond
(= x 1) 1
:else 0
))
(def hand
(map
;;fn
#(let [x %]
(cond
;;hearts
(< x 10) (* x -1)
(< x 13) -10
;;diamonds
(< x 23) (* (mod x 13) -1)
(< x 26) -10
;;clubs
(< x 36) (mod x 13)
(< x 39) 10
;;spades
(< x 49) (mod x 13)
(< x 52) 10
))
;;list
(take (rand-int 12) (repeatedly #(+ 1 (rand-int 52)))))))))
This would not be necessary if not for 2 things. First, I would like to condense this program down to one function if possible (and I think it /is/ possible!). Second, I need to use this variable at another point in my program so I need to be able to reference it somehow.
Anyway, when I try to evaluate the above function, it complains that it doesn't know "how to create ISeq from: clojure.lang.Var". (This is the error: IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Var clojure.lang.RT.seqFrom (RT.java:542)) I'm assuming this means that it doesn't know how to use my variable as a vector... but it seems to use it as a vector just fine when I define my variable outside of the function!
Any advice?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…