TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

π in Clojure

24 pointsby alrex021over 15 years ago

3 comments

ramchipover 15 years ago
Haskell version:<p><pre><code> 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 </code></pre> IMHO that was cleaner and easier than the Clojure code. I didn't really get the bindings thing.<p>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!
评论 #1122028 未加载
dschobelover 15 years ago
The post starts so beautifully... and then the JVM shows up.
mbrubeckover 15 years ago
I'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.)
评论 #1121147 未加载