Saturday, July 14, 2012

Never ending function

Today, I had a Clojure quiz for myself. How to write a function that print out a number and return a function that will print out an incremented number and return out a function with the same behavior again and again, never end.

For those who are familiar with Clojure might find it easy but for me it took a while and I couldn't solve it so I decided to start solving it with Ruby first.

This is my solution.
pi = ->x = 0 do
puts x
->{ pi[x + 1] }
end
# result
> pi[][][][][][][]
0
1
2
3
4
5
6
view raw pi.rb hosted with ❤ by GitHub
After that it was way more easier to port it to Clojure.
(defn pi
([] (pi 0))
([x] (println x) #(pi (+ x 1))))
; result
=> (((((((pi)))))))
0
1
2
3
4
5
6
view raw pi.clj hosted with ❤ by GitHub

No comments:

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...