title: Calculating a series approximation for pi & scheme syntax
body: <p>Im taking a run with scheme for the first time &amp; am trying write a simple recursive function which will calculate pi using the <a href="https://wikimedia.org/api/rest_v1/media/math/render/svg/fab3e3e4febf987b57159d81fd47995fb0af1240" rel="nofollow noreferrer">Leibniz formula</a>. The procedure takes in the accuracy needed and returns an appropriate pi approximation.</p>
  
  <p>for example: make-pi 0.001 -> 3.14109...</p>
  
  <p>Im getting caught up with the syntax however and am a lost in the syntax and proper way to call/return variables in scheme.</p>
  
  <pre><code>; Define count for number of loops, sum for pi estimate, and num/denom for calculating estimation in series
  (define count 1.0)
  (define sum 4.0)
  (define denomenator 3.0)
  (define numerator 4.0)
  
  ; make-pi gets accuracy needed as input ie (make-pi 0.001 =&gt; 3.1410926536210413
  (define make-pi
    (lambda (accuracy)
      ; determine if next fraction will be + or - based on number of iterations thus far
      (if (zero? sign count)
          ; add fraction if odd, subtract otherwise
          (+ sum (/ numerator denomenator))
          (- sum (/ numerator denomenator)))
      (define (check-accuracy sum)
        ; use check accuracy with current sum
        (if (zero? check-accuracy)
            ;return sum if within needed accuracy
            sum
            ; update count and new denom values if not accurate enough
            ; loop back if sum is not accurate enough
            (begin
              (+ count 1)
              (+ denomenator 2)
              (make-pi (sum)))))))
  
  
  
  ; if interation is even return 1 else 0
  (define sign
    (lambda (count)
      (if (even? count))
    1
    0))
  
  ; if pi - sum is within desired accuracy, return 1 else 0
  (define check-sum
    lambda (sum)
    (define check-accuracy
      lambda (accuracy)
  
    (if ((- 3.14159265358979 sum) &lt; (abs(accuracy))))
    1
    0))
  </code></pre>