Oh, well this is fun -- with bleeding edge clojure I get the right answer,
but with 1.6.0 I see the same results you did.

On Thu Feb 12 2015 at 11:47:54 AM Michael Blume <blume.m...@gmail.com>
wrote:

> Strange, when I run your code I don't get 9 or 15
>
> On Thu Feb 12 2015 at 11:02:00 AM Jorge Marques Pelizzoni <
> jorge.pelizz...@gmail.com> wrote:
>
>> Hi, there! Please bear with me as I am very new to Closure (this is my
>> second program ever) but have a kind of solid Haskell background.
>>
>> I was trying to get a version of this Haskell code:
>>
>> divides x y = mod x y == 0
>> primeub x = div x (if even x then 2 else 3)
>> isprime primes x = all (not . divides x) (lowerprimes x)
>>     where
>>         lowerprimes x = takeWhile (<= primeub x) primes
>>
>> primes = 2 : filter (isprime primes) [3..]
>>
>>
>> which works fine. E.g.: take 10 primes == [2,3,5,7,11,13,17,19,23,29].
>> In Closure, I got this:
>>
>> (defn divides? [x y] (zero? (mod x y)))
>> (defn prime-ub [x] (/ x (if (even? x) 2 3)))
>> (defn lower-primes [primes x] (let [ub (prime-ub x)]
>>                               (take-while #(<= % ub) primes)))
>> (defn prime? [primes x] (not-any? #(divides? x %)(lower-primes primes x
>> )))
>>
>> (defn primes [] (let [primes' (atom nil)]
>>                  (reset! primes' (cons 2 (filter #(prime? @primes' %)
>> (drop 3 (range)))))))
>>
>> However, I am getting (take 10 (primes)) == (2 3 5 7 9 11 13 15 17 19)
>> (please notice the undesirable presence of 9 and 15 there...).
>>
>> Any ideas why this is happening? Thanks in advance.
>>
>>
>>  --
>> 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/d/optout.
>>
>

-- 
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/d/optout.

Reply via email to