I did translation to minimal Scheme implementation of Norvig written in Python (http://www.daniweb.com/software-development/python/threads/359370/norvig-an-even-better-lisp-interpreter-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.

Edited by pyTony: Title revision

    (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))

IT/Science/Contracts/Religious translation/interpreting FIN-ENG-FIN
Python programming

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.