Monday, August 31, 2020

SICP in Clojure: Chapter 1, Exercise 38

 This is my Clojure solution to Chapter 1, Exercise 38:

(ns sicp.ch1.ex38
  (:require [sicp.ch1.ex37 :as ch1-ex37]))

(defn d
  [i]
  (let [j (- i 2)]
    (if (zero? (mod j 3))
      (* 2 (inc (/ j 3)))
      1)))

(comment
  (double (+ 2
             (ch1-ex37/cont-frac (constantly 1)
                                 d
                                 10))) ; => 2.718281718281718
  #__)