#clojure logs

2008-06-06

12:27dudleyfrhickey: If you get a second:
12:27dudleyfhttp://github.com/dudleyf/clojure-bin/tree/master/clojure
12:28dudleyfIt's a little script to run Clojure programs
12:29rhickeydudleyf: Thanks. I'm actually a bad candidate for evaluating this, being the producer rather than a consumer of Clojure. Why not post to the group and start a discussion?
12:31dudleyfWill do.
12:32arbschtdudleyf: it could be helpful if one could switch the path to the java binary
12:42dudleyfarbscht: I was going to make it relative to JAVA_HOME
12:43arbschtdudleyf: that could work
12:46dudleyfrhickey: I know it's come up before, but what are your current thoughts about adding string interpolation?
12:46rhickeydudleyf: I'm not opposed, depending on how it's done
12:59rhickeycgrand: thanks for helping out on the group
13:02rhickeyLeafw: did doubles/floats et al help out with your macro?
17:51slavahi rhickey!
17:54rhickeyhi
18:05Lau_of_DKGuys, I suppose you've all seen Richs (def fib-seq) on the Wiki, which seeds 0 1 and then returns a lazy list of fibs with some type of caching. Is there anyway to do a similar (def primes) or do I have to use (defn) and make a reqular function?
18:13scgilardifib-seq defines a function and then evaluates it to produce the sequence lazily. It could have been done in two steps with an explicit helper function. This page (at the bottom) has an implementation of a lazy list of primes in common lisp that looks like it would be easy to translate to clojure. Is your goal to produce a lazy sequence of primes? http://www.lassila.org/blog/archive/2006/05/fun
18:13scgilardi_with_lazy_e_1.html
18:13scgilardihttp://www.lassila.org/blog/archive/2006/05/fun_with_lazy_e_1.html
18:14Lau_of_DKLooking at the page now, but yea it was 2 part, 1) produce a lazy list of primes , 2) do it as a (def) because as I understood the wiki it gave some advantages like cached results
18:16scgilardithe caching of results comes from using lazy-cons which can be done in or out of a defn.
18:16Lau_of_DKok, good
18:18Lau_of_DK"Name a sequence that is seeded with [0 1] and forego the function so that instead of starting over with each call, you get a "cached infinite seq, lazily extended."
18:18Lau_of_DKA bit confusing since both examples use lazy-cons
18:18Lau_of_DKno wait, of course the function calculates from scratch when its called
18:20scgilardiright, so it is significant that it's a def. the lazy sequence stays around across accesses of the sequence. cool.
18:20scgilardithe caching part is mentioned in (doc lazy-cons)
18:20Lau_of_DKk, so I gotta work out a def primes for it to be effective
18:24scgilardiseems right to me
19:07Lau_of_DKHmm - I need brains, check this out
19:08Lau_of_DK(defn prime?
19:08Lau_of_DK [n]
19:08Lau_of_DK (every? (fn [x] (> (rem n x) 0)) (range 2 n)))
19:08Lau_of_DK(def primes
19:08Lau_of_DK (concat [1 2]
19:08Lau_of_DK ((fn rprime [x]
19:08Lau_of_DK (let [x1 (+ x 1)
19:08Lau_of_DK x2 (+ x 2)]
19:08Lau_of_DK (lazy-cons (if (prime? x) x (rprime x1))
19:08Lau_of_DK (if (prime? x1) x1 (rprime x2))))) 3)))
19:08Lau_of_DKuser> (take 5 primes)
19:08Lau_of_DK(1 2 3 5 7)
19:08Lau_of_DKSo far so good right? but if I -take- more than 5 primes, it throws a StackOverFlow exception...?
19:17scgilardi(defn sieve [s]
19:17scgilardi (lazy-cons (first s)
19:17scgilardi (sieve (filter
19:17scgilardi (fn [x]
19:17scgilardi (not
19:17scgilardi (= (rem x (first s)) 0)))
19:17scgilardi (rest s)))))
19:17scgilardi (defn primes []
19:17scgilardi (sieve (iterate inc 2)))
19:17scgilardithat's from lou franco's blog.
19:18scgilardi(defn sieve [s]
19:18scgilardi (lazy-cons (first s)
19:18scgilardi (sieve (filter
19:18scgilardi #(not (= (rem % (first s)) 0))
19:18scgilardi (rest s)))))
19:18scgilardi(defn primes []
19:18scgilardi (sieve (iterate inc 2)))
19:18Lau_of_DKIts a different approach, but if def caches the results, by principle it should not overflow ever right?
19:18scgilardiactually the latter is what I'm using. it runs out of heap space someplace between 1000 and 10000.
19:19Lau_of_DKHmm... This is a little weird, I've never had any trouble doing such computations in SBCL
19:19scgilardiwell the heap does have a fixed size, but I don't think we're near that. (the size is tunable in the java command line)
19:20scgilardiI'm having trouble turning this all into something that can use "recur" to avoid stack overflow, but this heap overflow is a different issue.
19:21Lau_of_DKOk
19:22Lau_of_DKI'm a bit weak on that side of understanding the mechanics of the compiler
19:31scgilardiwith this
19:32scgilardi(defn sieve [s]
19:32scgilardi (lazy-cons (first s)
19:32scgilardi (sieve (filter
19:32scgilardi #(not (= (rem % (first s)) 0))
19:32scgilardi (rest s)))))
19:32scgilardi(def prime-seq
19:32scgilardi (lazy-cons 2 (sieve (iterate #(+ % 2) 3))))
19:32scgilardiand a 256 MB heap I'm able to get 1900 primes before I run out of heap space
19:33Lau_of_DKSounds good - How did you set the heap to 256 megs?
19:33scgilardiwith a 512 MB heap, I'm able to get 2000, but not 3000.
19:34scgilardiThese are the memory related options for the "java" command line that launches clojure "-Xms32M -Xmx256M"
19:34scgilardims is the initial heap size and mx is the max
19:34Lau_of_DKah, thats useful, thanks alot
19:34scgilardiyou're welcome