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