3 ms·
π in Clojure
- dschobel 17y agoThe post starts so beautifully... and then the JVM shows up.
- mbrubeck 17y agoI'm amused that news.arc automatically capitalized the first letter of this post. (It also makes lots of iPhone/iPad stories look kind of weird.)
- alrex021 17y agoYou mean why it didn't right? If so, reason is that the first character of this post is actually a pi symbol. (c-c c-v -> editor)
- mbrubeck 17y agoI thought it had changed lowercase π to capital Π... but I see now that it was just a trick of the font. (HN appears in Verdana on my computer, and Verdana's lowercase pi looks like most typefaces' capital Pi.)
- ramchip 17y agoHaskell version: import Data.Number.Fixed pis :: [Fixed Prec50] pis = map termToPi $ iterate update (1, 1/(sqrt 2), 1/4, 1) where update (a,b,t,p) = (a',b',t',p') where a' = (a+b)/2 b' = sqrt(a*b) t' = t - p * sqr(a - a') p' = 2 * p termToPi (a,b,t,_) = sqr(a + b) / (4*t) sqr x = x*x main = putStrLn . show $ pis !! 20 -- 3.14159265358979323846264338327950288419716939937583 IMHO that was cleaner and easier than the Clojure code. I didn't really get the bindings thing. Edit: Out of curiosity I checked with Debug.Trace to see how it runs, and termToPi only gets called once for the term that was requested, even though I said "map termToPi". Fun!