Hello, the current state of Conway's Prime Machine is at http://paste.lisp.org/+21BR
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. Thank you for the hints. Regards, alux On 14 Feb., 16:06, Johnny Kwan <johnny.c.k...@gmail.com> wrote: > On Feb 14, 2010, at 8:58 AM, Laurent PETIT wrote: > > > > > 2010/2/14 alux <alu...@googlemail.com>: > >> Hello Sean, > > >> thank you for the answer. > > >> I used letfn not for recursive swearing, but for the localness. I > >> thought the functions to be so special, > >> nobody else will use it, so I put it into conway-PM. Is there a non > >> recursive let for functions? > > > Hello, > > > in this case, you can just use let: > > > user=> (let [some-fn (fn [] "hello!")] > > (println (some-fn))) > > hello! > > nil > > user=> > > > HTH, > > > -- > > Laurent > > FWIW, you can always define functions privately with defn-. I prefer that > style. > > Johnny > > > > >> Thanks for the hint about Lisppaste, didnt know that. > > >> Regards, alux > > >> On 13 Feb., 19:25, Sean Devlin <francoisdev...@gmail.com> wrote: > >>> Alux, > >>> Welcome to Clojrue! Thanks for posting this example. > > >>> At first glance I would combine power-of-two? and what-power-of-2 into > >>> one fn. Also, I would change the order you wrote the method calls in > >>> to favor the .method style > > >>> (defn power-of-2 > >>> "Returns log_2(n) iff n is an exact pwoer of 2. nil otherwise" > >>> (if (= (.bitCount (big-int n)) 1) > >>> (dec (.bitLength (big-int n)))) > > >>> Also, letfn is for mutually recursive fns (you know, the kind that > >>> swear at each other :). I would move big-int, step & power-of-2 into > >>> their own defns. That should clean up your definition of conway-PM. > > >>> Sean > > >>> PS - Do you use github or lisppaste? The general practice is to put > >>> code in a pastebin, and simply include a link in the mailing list. > > >>> On Feb 13, 11:48 am, alux <alu...@googlemail.com> wrote: > > >>>> Hi, > > >>>> I just finished my first (very small) Clojure program. I come from > >>>> Java, so it will be everything but idiomatic Clojure, so I post it > >>>> here and you may give as much criticism as you want. I'm here to > >>>> learn. > > >>>> It implements JHConway prime machine. The program does not want to be > >>>> a quick prime generator (the algorithm is interesting but not quick at > >>>> all), but it shall be/become a good implementation of this algorithm. > > >>>>http://www.jstor.org/pss/2690263(Thefirstpage is enough to > >>>> implement the algorithm, even if the explanation will come on the next > >>>> pages only.) > > >>>> Started like: > > >>>> (conway-PM) > > >>>> It came up to 563 after about 6 hours on my 1.2 GHz Centrino ;-) > > >>>> Thats the program, feel free to tell me stuff (or to ignore me, would > >>>> be a lessen too :) > > >>>> (defn conway-PM [] > >>>> (let [ > >>>> factors '(17/91 78/85 19/51 23/38 29/33 77/29 95/23 > >>>> 77/19 1/17 11/13 > >>>> 13/11 15/14 15/2 55/1) > >>>> big-int-class (. 999999999999999999999999999999999 > >>>> getClass)] > >>>> (letfn [ > >>>> (big-int [n];"makes a bigint from int, keeps n > >>>> if bigint already" > >>>> (let [current-class (. n getClass)] > >>>> (if (= current-class > >>>> big-int-class) n > >>>> (. java.math.BigInteger > >>>> valueOf n)))) > >>>> (power-of-two? [n];"true iff the integer n is an > >>>> power of 2." > >>>> (= (. (big-int n) bitCount) 1)) > >>>> (what-power-of-2 [n];"gets n from 2^n" > >>>> (- (. (big-int n) bitLength) 1)) > >>>> (step ;"Multiplies with the first factor to give > >>>> an integer." > >>>> [n, unused-factors] > >>>> (let [factor (first unused-factors) > >>>> rest-factors (rest > >>>> unused-factors) > >>>> dummy (* n factor)] > >>>> (if (integer? dummy) > >>>> dummy > >>>> (step n rest-factors))))] > >>>> (loop [seed 2] > >>>> (let [next (step seed factors)] > >>>> (if (power-of-two? next) > >>>> (println > >>>> (what-power-of-2 next))) > >>>> (recur next)))))) > > >>>> Regards, alux > > >> -- > >> 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 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 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