Alux, This is good progress, keep up the good work. Here's my implementation w/Jarkko's suggestions built in. Take a look at this AFTER you complete your next iteration :)
http://gist.github.com/305521 I've changed the following * Imported java.math.BigInteger * Used the instance? predicate to test if an object is a BigInteger in your big-int fn. * I added type hints to special-log. This lets Clojure use the specific class methods for the object instead of reflection. The result is the code is much faster. * removed the letfn and placed step in the normal let block. There's no mutual recursion, so let will do the job. * Wrote the producing fn in terms of iterate, so the result is now a lazy list. Sean On Feb 16, 6:38 am, Jarkko Oranen <chous...@gmail.com> wrote: > On Feb 16, 12:26 pm, alux <alu...@googlemail.com> wrote: > > > Hello, > > > the current state of Conway's Prime Machine is athttp://paste.lisp.org/+21BR > > Instead of using a quoted list, a vector is more idiomatic in Clojure. > > > > > I'l go on learning. The next state should be seperation of print and > > produce. Currently (conway-pm) doesnt return stuff. I dont know if > > Clojure can produce infinite lists, like Haskell, and print the items > > as they come. > > It can. They're just called infinite sequences. For example, (iterate > inc 0) produces an infinite sequence of integers from 0 onwards. You > can also construct your own infinite sequences using the lazy-seq > macro in a pattern like the following: > > (defn count-down [x] > (lazy-seq (cons x (count-down (dec x))))) ; lazy-seq doesn't > actually evaluate the cons until it's requested > > However, often you should start by looking at the core library and see > if there already exists a function to produce a list that you need, > and only afterwards construct things from scratch. For example, > "repeatedly" and "iterate" are common seq-producers, and "map" and > "filter" are used to transform them. They're all lazy, so infinite > seqs are not problematic. > > There is one thing you need to look out for though: Never define a > global reference to an infinite seq. The items in a sequence are > cached, so if you define a global reference to the head, no part of > the seq will ever be garbage collected and its memory usage will be > unbounded. -- 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