On 16 Nov., 23:31, Simon Brooke <[EMAIL PROTECTED]> wrote: > Has anyone written a very simple introduction to Clojure for LISP > hackers? I've spend an evening playing with it pretty intensively, and > thus far I haven't got a thing to work. I've > readhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L..., > but it hasn't helped me. > > In LISP: > > * (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n 1)))))) > FACT > * (fact 10) > 3628800
What you could do if you were interested in a memoized version, then this Clojure code may be what you like: (def facts (lazy-cat [1] (map * facts (iterate inc 1)))) (nth facts 5) ==> 120 So instead of having a function here we can see facts more like the set of all factorials. Or try it with (def fibs (lazy-cat [1 1] (map + fibs (drop 1 fibs)))) When I time (nth fibs 80000) it takes 3 seconds on my machine. But when I do it the next time it’s done in 20 msecs. And as I already have the first 80k it takes only 35 msecs to do (nth fibs 81000) now. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---