11.sld 774 B

123456789101112131415161718192021222324252627
  1. (define-library (aop 11)
  2. (import (scheme base))
  3. (export last-pair append! lookup)
  4. (begin
  5. (define (last-pair x)
  6. (if (pair? (cdr x))
  7. (last-pair (cdr x))
  8. x))
  9. (define (append! ls1 ls2)
  10. (if (pair? ls1)
  11. (begin
  12. (set-cdr! (last-pair ls1) ls2)
  13. ls1)
  14. ls2))
  15. (define (lookup obj table success-proc failure-proc)
  16. (letrec ((lookup (lambda (table)
  17. (if (null? table)
  18. (failure-proc)
  19. (let ((pr (car table)))
  20. (if (equal? (car pr) obj)
  21. (success-proc pr)
  22. (lookup (cdr table))))))))
  23. (lookup table)))))