title: Clojure: Beginners question on passing vectorized string to function
body: <p>I'm new to Clojure.  I was trying to get the following code to generate anagrams of the word 'rat'.
  Ideally I'd like to start with a string, convert it to a vector -- but for now I tried starting with a vector.  I've tried many variants and getting compiler errors.  I understand what the errors mean -- but not sure what to do in clojure to fix them.  The current code produces this error: "clojure.lang.PersistentVector cannot be cast to clojure.lang.IAtom".  </p>
  
  <pre><code>(ns clojure.examples.anagram
  (:gen-class))
  
  (defn generatePermutations [v n] 
     (if (zero? n) 
        (do (println (apply str v)) v) 
  
        (loop [i 0 a v] 
           (if (&lt; i n) 
              (do 
                 (let [a (generatePermutations a (dec n))] 
                 (recur (inc i) (swap! a (if (even? n) 0 i) n)))) 
              (generatePermutations a (dec n)))))) 
  
  (let [word (vec ['r' 'a' 't'])]
     (generatePermutations word 3))
  </code></pre>
  
  <p>Thanks in advance for any help!</p>
  
  <p>Here is the java version of the code.  This version takes the word "rat" (or 
  any other word) as a command line argument.  For the Clojure version, I was running it in an online IDE and there wasn't an easy way to pass an argument so I was attempting to hardcode the input.</p>
  
  <pre><code>public class Anagram {
      public static void main(String[] args) {
          if (args.length !=1) {
              System.err.println("Exactly one argument is required");
              System.exit(1);
          }
          String word = args[0];
          generatePermutations(word.toCharArray(),word.length()-1);
      }
  
      private static void generatePermutations(char[] a, int n){
          if (n ==0){
              System.out.println(String.valueOf(a));
          } else {
              for (int i = 0; i &lt; n; i++) {
                  generatePermutations(a, n-1);
                  swap(a,n%2 == 0?0: i, n);
              }
              generatePermutations(a,n-1);
          }
      }
  
      private static void swap (char[] a, int i, int j){ 
          char saved = a[i];
          a[i]= a[j];
          a[j] = saved;
      }
  }
  </code></pre>