#clojure logs

2008-04-21

07:08jteoi keep getting stack overflows (trying to find a large prime).
09:43vincenzjteo: show me the code
09:44jteolemme pastebin it. i think i don't quite grok lazy sequences.
09:45jteoi managed to solve it by using an iterative approach using loop.
09:45rhickey_paste.lisp.org has Clojure support: http://paste.lisp.org/new/clojure
09:49vincenzrhickey_: Hey if I roll my own language with some ideas of clojure (and obviously mention their origin) would you mind?
09:49vincenzs/of/from
09:49lisppaste8jteo pasted "primes" at http://paste.lisp.org/display/59467
09:49rhickey_what would you do differently?
09:50vincenzrhickey_: several things, some of which wouldn't be supported in your model
09:50vincenzWell, at least not by the jvm
09:50vincenzThe fundamental thing I want are delimited-continuations in the presence of stm
09:50vincenzSince that requires me rolling a new lang, I'll prolly make some other changes as well, as well s keep some ideas
09:51vincenzrhickey_: place it somewhere between clojure, haskell and arc
09:51vincenzwell mostly between clojure and haskell :)
09:51vincenzand scheme, cause of the dc's
09:52vincenz(The only neat thing from arc, though I think you support this as well are fun-callable data structures)
09:52rhickey_vincenz: well, few of the ideas in Clojure are novel, everyone borrows from the past - good luck!
09:52vincenzrhickey_: thanks :)
09:52vincenzBtw, you're welcome to join #oasis
09:52vincenzIt's a bit of a social ltu for freenode
09:53vincenzOften silent, but we have bouts of interesting conversations, and a lot of smart people
09:54jteoltu?
09:56Chouserhttp://lambda-the-ultimate.org/
09:57Chouser...where I go to remind myself how little I know about anything.
09:58jteoah.
10:14rhickey_jteo: what's the problem with the primes you pasted?
10:15jteorhickey_: stack overflow.
10:23cgrandrhickey, in Compiler.java:1790 shouldn't it be "Class classForName(String)" instead of "Class forName(String)"? (else I get MethodNotFound...)
11:51cgrandjteo: I think your code chains filters and, to get a new prime, it has to go through all the filters... and when there are too many filters your stack explodes.
11:52jteocgrand: i guess so. I was trying to figure out how to iterate over a lazy seq.
11:54jteoie. some way to skip forward to the nth item in the lazy-seq, without consuming large amounts of memory/cpu.
11:55jteoobviously loop is one way.
12:18Modiusjteo: Depending on how the lazy sequence is implemented under the hood, looping through may not alter the CPU usage of any given stage of iteration, nor the memory footprint.
12:18jteotrue.
12:19Modiusjteo: What can lead to memory usage also are lazy sequences that make use of memoized links (some require these, e.g. certain self-referencing list solutions) - but the link back to the head (if you somehow keep one) causes all results to be preserved until the end of the computation, limiting how far you can traverse the sequence, or how many can be traversed in parallell with other actions that also use ram.
12:19jteo:)
12:20Modiusjteo: The cliched haskell self-referencing fibonacci highlights this effect - AFAIK spking RAM proportional to N when obtaining the Nth item.
12:21jteogiven that it's mostly run for small values of N..
12:21jteo(eg. in tutorials)
12:25ModiusI believe Clojure has the raw tools required to solve these problems (macros + lambdas), and said solution would be inside its concurrency/STM model.
12:27ModiusBy "problem" I mean "ability to programmatically model solutions in this manner", not that it's a language problem per se
12:29vincenzModius: Err..
12:29vincenzModius: that's a lot of BS :)
12:29Modiusvincenz: sorry
12:30vincenz1) recursive fibonacci in Haskell is just for tutorials
12:30vincenz2) if you do not want to keep it around, make it a function
12:30vincenzfib n = ...your memoized version !! n
12:31vincenz3) If you do not like to use space, then just write it recursively
12:31vincenzthe whole point of the memoized version is to trade-off computation for storage
12:32Modiusvincenz: Does writing it recursively partially memoize? Otherwise it'll become infinitely slow before the 30th element.
12:32vincenzAnywho, a bit weak to bash on $(LANGUAGE) if you do not intimately know said $(LANGUAGE) outside of the $(LANGUAGE) forum where noone is there to watch wat you say.
12:33vincenzModius: just write it iteratively?
12:33vincenzuh?
12:33Modiusvincenz: (On bashing) agreed, wasn't my intend, just to describe an effect. And I'd discussed it on #haskell by the way.
12:33vincenzs/uh/duh
12:33Modiusvincehz: I did try to say "cliched haskell self-referencing fibonacci" - I wasn't indicting a language; but an expression form under memoization.
12:33vincenzlet fib n = worker 0 1 1 where worker a b m = if m == n then b else worker b (a+b) (m+1)
12:34vincenzModius: But the leakage-problem is acknowleged
12:34vincenzModius: It's just a trade-off really, do you want to use CPU or do you want to use memory, and granted, if you're not careful you can leak more than you want to.
12:35Modiusvincenz: I'm not going to hawk my own library in someone else's pond; but I have one where I was able to do both -self-referencing AND memoization; but memoization only between the links, not to the head.
12:36vincenzModius: IIUC, you memoized the last two but not the whole thing?
12:36Modiusvincenz: I don't consider the "leakage problem" that the cliched fibonacci highlights a haskell problem; but was trying to use it to describe an effect.
12:36lisppaste8cgrand pasted "a naive primes seq" at http://paste.lisp.org/display/59475
12:37cgrandjteo: I guess this is not what you look for?
12:45jteocgrand: neat. now let me try to understand how it works. ;)
12:54jteoi'm having difficulty understanding why this one doesn't cause a stack overflow compared to the sieve implementation i tried.
13:05cgrandjteo: in yours, when you have already got 3, 5 and 7 to get the next prime, you ask to your seq (which filter out multiples of 7) for the next item, which asks to its parent seq (filter out 5x) which asks to its parent seq (filter out 3x) which asks to the odd numbers seq. In mine I just loop over the list of known primes (in prime?).
13:05jteousing "every?" you mean?
13:10cgrandyes, every? is just a loop
13:11jteoah.
22:54Chouserdoes #(filter identity %) deserve its own built-in name?
22:56Chouseror maybe add an arity-one option to filter?