Hello,

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. 

So the issue is the following. I've implemeted a function that computes the 
prime numbers from an interval (up to a limit). 

(defn gather_primes_in_range [range_start range_end target_number 
prime_list]
(if (or (= 0 target_number) (> 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 (< range_start 2)
(gather_primes_in_range 2 range_end target_number [])
(gather_primes_in_range range_start range_end target_number [])
)
)

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. 

Basically what I tried is, have somewhere global declared:

(def PRIMES_FOUND_SO_FAR #{})

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 swap! and atom, or set! but could not make 
it to work here in any situation.

Best regards,
Bogdan

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to