Calculating impedance for Norvig's Scheme subset in Python implementation



I did translation to minimal Scheme implementation of Norvig written in Python ( of the impedance code defined in classic book Lisp by Patric Henry Winston and Berthold Klaus Paul Horn from year 1981 (first computer book I ever bought). Errata: diagram has 10 MOhm when the code listed has 1 MOhm.

I could not get eval to see the omega given as parameter to impedance in l and r functions so I had to do define in caller before invoking the function instead. If anybody knows the way to do it in Scheme, I would happy to hear about it. I do not know Scheme and I am trying to import my 1980's MacLisp studies to learn it a little.

About the Author

IT Pro doing Eng-Fin-Eng translations

    (define (newline) (display "\n"))
    (define circuit-a
            (quote (series (r 1.0)
                      (parallel (series (r 100.0)
                                        (l 0.2))
                      (parallel (c 0.000001)
                                (r 1000000.0))))))

    (define (series a b) (begin
                          (+ a b)))

    (define (parallel a b)(let ((res (/ 1. (+ (/ 1. a) (/ 1. b)))))
    (define (r x) x)
    (define (l x) (* (* omega x) 1i))
    (define (c x) (* 1i (/ -1.0 (* omega x))))

    (define (impedance circuit)
     (eval circuit))

    (display circuit-a)
    (define omega 2179.44)
    (display "Omega: ")
    (display omega)
    (display ". Impedance = ")
    (display (impedance circuit-a))
    (define omega 2207.99)
    (display "Omega: ")
    (display omega)
    (display ". Impedance = ")
    (display (impedance circuit-a))