Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution:
Generation of get-prop


Here is my solution:

(define (configure-get-prop comparison not-found-value) (letrec ((get-prop (lambda (key property-list) (cond ((null? property-list) not-found-value) ((null? (cdr property-list)) (error "Malformed property list")) ((comparison key (car property-list)) (list key (car (cdr property-list)))) (else (get-prop key (cdr (cdr property-list)))))))) get-prop))

Notice the use of the letrec namebinding in order to provide for recursion in the generated function.