title: change values from global variable in Clojure
body: <p>I'm a total beginer in Clojure and I've ran into a problem that I'm not even sure if can be done in Closure. </p>
  
  <p>So the issue is the following. I've implemented a function that computes the prime numbers from an interval (up to a limit). </p>
  
  <pre><code>(defn gather_primes_in_range [range_start range_end target_number prime_list]
      (if (or (= 0 target_number) (&gt; range_start range_end) (= FIND_MORE_PRIMES false)) 
          prime_list
          (do
              (if (is_prime? range_start)
                  (gather_primes_in_range (+ range_start 1) range_end (- target_number 1) (conj, prime_list, range_start))
                  (gather_primes_in_range (+ range_start 1) range_end target_number prime_list)
              )
          )
      )
  )
  
  (defn find_nr_of_primes_in_range [range_start range_end target_number]
      (if (&lt; range_start 2)
          (gather_primes_in_range 2 range_end target_number [])
          (gather_primes_in_range range_start range_end target_number [])
      )
  )
  </code></pre>
  
  <p>This works just fine. But what I want now is to have a global variable that should store on each method call the primes that are found in a variable to lookup later. In other languages like Python, Ruby or Scala I would just do this by having a Set to which I add entries before returing from the function. But in Clojure I have no ideea how to go around this. </p>
  
  <p>Basically what I tried is, have somewhere global declared:</p>
  
  <pre><code>(def PRIMES_FOUND_SO_FAR #{})
  </code></pre>
  
  <p>And then somehow on return add the entries to this variable. Is this possible at all in Clojure and if so how? I've tried on other variables to change their values using either <code>swap!</code> and <code>atom</code>, or set! but could not make it to work here in any situation.</p>