On May 26, 2009, at 2:59 PM, kyle smith wrote:
> > I have written code that will randomly guess the mathematical form of > a list of xy ordered pairs. My code and a sample run are in guess- > check.clj in the files section. The final sum of squares is > fantastic! This code is just for fun, but I would appreciate some > feedback. I would do make-args like this: (defn make-args [] (take (inc (rand-int 3)) (repeatedly #(if (< 0.2 (rand 1)) (random-lst-elt vars) (random-lst-elt nums))))) Not sure you need n-random-lst-elts since you never call it. I would probably do new-random-lst with cons rather than a quasiquote, like this: (defn new-random-list [] (let [fun (random-lst-elt funs)] (cons (first fun) (list (second fun))))) But I haven't run it to see if it has the same interface. I would probably use some or contains? instead of making the member function. I would probably write remove-nth like this: (defn remove-nth [n seq] (concat (take (- n 1) seq) (drop n seq))) This strikes me, rightly or wrongly, as more efficient in the long run and won't remove nil values from the sequence. Maybe you wanted that behavior? I didn't get much further; it looks pretty interesting though. :) I would probably try to think of a way to rewrite it with less reliance on mutable data structures, if possible. Emulating them functionally isn't always great for performance or readability. "Purely Functional Data Structures" by Chris Okasaki can help with this. I would consider replacing some of your cond's with condp's like this: (condp > (rand) 0.1 (println "it's less than .1") 0.8 (println "it's less than .8") 1.0 (println "otherwise case")) Oh, and (rand) does the same thing as (rand 1), AFAIK. Hope you're enjoying Clojure as much as I am! Cheers, — Daniel Lyons http://www.storytotell.org -- Tell It! --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---