Lisp001Lisp002

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 3 Years Ago by pyTony: Title revision

(begin
    (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)))))
                            res))
    (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)
    (newline)(newline)
    (display "Omega: ")
    (display omega)
    (display ". Impedance = ")
    (display (impedance circuit-a))
    (newline)
    (define omega 2207.99)
    (newline)
    (display "Omega: ")
    (display omega)
    (display ". Impedance = ")
    (display (impedance circuit-a))
    (newline)
)

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

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.