srfi-17.scm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (define-syntax set!
  2. (syntax-rules ()
  3. ((set! (?e0 ?e1 ...) ?v)
  4. ((setter ?e0) ?e1 ... ?v))
  5. ((set! ?i ?v)
  6. (scheme-set! ?i ?v))))
  7. (define (setter proc)
  8. (let ((probe (assv proc setters)))
  9. (if probe
  10. (cdr probe)
  11. (error "No setter found" proc))))
  12. (define (set-setter! proc setter)
  13. (let ((probe (assv proc setters)))
  14. (if probe
  15. (set-cdr! probe setter)
  16. (scheme-set! setters
  17. (cons (cons proc setter)
  18. setters)))
  19. (unspecific)))
  20. (define (car-setter proc)
  21. (lambda (p v)
  22. (set-car! (proc p) v)))
  23. (define (cdr-setter proc)
  24. (lambda (p v)
  25. (set-cdr! (proc p) v)))
  26. (define setters
  27. (list (cons setter set-setter!)
  28. (cons vector-ref vector-set!)
  29. (cons string-ref string-set!)
  30. (cons car set-car!)
  31. (cons cdr set-cdr!)
  32. (cons caar (car-setter car))
  33. (cons cdar (cdr-setter car))
  34. (cons cadr (car-setter cdr))
  35. (cons cddr (cdr-setter cdr))
  36. (cons caaar (car-setter caar))
  37. (cons cdaar (cdr-setter caar))
  38. (cons cadar (car-setter cdar))
  39. (cons cddar (cdr-setter cdar))
  40. (cons caadr (car-setter cadr))
  41. (cons cdadr (cdr-setter cadr))
  42. (cons caddr (car-setter cddr))
  43. (cons cdddr (cdr-setter cddr))
  44. (cons caaaar (car-setter caaar))
  45. (cons cdaaar (cdr-setter caaar))
  46. (cons cadaar (car-setter cdaar))
  47. (cons cddaar (cdr-setter cdaar))
  48. (cons caadar (car-setter cadar))
  49. (cons cdadar (cdr-setter cadar))
  50. (cons caddar (car-setter cddar))
  51. (cons cdddar (cdr-setter cddar))
  52. (cons caaadr (car-setter caadr))
  53. (cons cdaadr (cdr-setter caadr))
  54. (cons cadadr (car-setter cdadr))
  55. (cons cddadr (cdr-setter cdadr))
  56. (cons caaddr (car-setter caddr))
  57. (cons cdaddr (cdr-setter caddr))
  58. (cons cadddr (car-setter cdddr))
  59. (cons cddddr (cdr-setter cdddr))))