srfi-17.scm 1.8 KB

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