0
votes

I have created an atom, that contains a vector:

(def name-seq (atom ["A" 1]))

Within the swap! operation, I need to increment the number that's the last part of the vector. Here's what I am trying:

(swap! name-seq #(["A" (inc (last @%))]))

I get the following error: ClassCastException clojure.lang.PersistentVector cannot be cast to java.util.concurrent.Future clojure.core/deref-future (core.clj:2108)

What am I doing wrong here?

2
That worked - so, swap! sends the deref-ed atom to the given function. Thanks! - arnab
weird. I added a comment and SO removed the original comment from @loki. Thanks anyway! - arnab

2 Answers

1
votes

Thanks to @loki for the answer via a comment. The swap! function sends the deref-ed atom to the swapping function. Hence I needed to remove the deref that I was doing with @ from my solution:

(swap! name-seq #(["A" (inc (last %))])).

1
votes

If your name-seq is a fixed-length vector, then you may use update-in function to do so:

(swap! name-seq #(update-in % [1] inc))