by shagie · 2w ago · 0 comments
When done with the assignment I asked the emacs fan in then lab to look at it and his comment was "you write beautiful C in lisp."
https://www.ee.torontomu.ca/~elf/hack/real-programmers.html
... Besides, the determined Real Programmer can write FORTRAN programs in any language.
---My first revelation with functional programming was when I was dabbling with Clojure based on a Coding Horror question with giving a person being given an algorithim more difficult than Fizzbuzz (which has been memorized)... compute e or pi were the ones that I thought of.
pi / 4 = 1/1 - 1/3 + 1/5 - 1/7 ...
I was trying to figure out if I could use cycle to handle that and then the lightbulb for first class functions hit him.
The solution I came up with was:
(defn pi
([] (float (* 4 (pi 1 0.01 0 true))))
([term tol accum pn]
(let
[t (/ 1 term)
a ((if pn + -) accum t)]
(if (< (* 4 t) tol)
a
(pi (+ term 2) tol a (not pn))
)
)
)
)
The lightbulb was the `((if pn + -) accum t)` bit where `pn` was a boolean that flipped each call... and `(if pn + -)` returned the function.That was May 9th, 2013 (I can find where I was explaining it in a web chat that is still out there).
No comments yet.