test-doodl.scm 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; ((method () 1)) => 1
  3. ; ((method () 1) 2) => error
  4. ; ((method (x) 1) 2) => 1
  5. ; ((method ((x <symbol>)) 1) 2) => error
  6. ; ((method ((x <symbol>)) 1) 'foo) => 1
  7. ; ((method ((x <symbol>)) (next-method)) 'foo) => error
  8. (define-generic-function elt (s))
  9. (define-method elt ((x <vector>) y)
  10. (vector-ref x y))
  11. ; (elt '#(a b c) 1) => b
  12. (define-method elt ((x <string>) y)
  13. (string-ref x y))
  14. (define-method elt ((x <list>) y)
  15. (list-ref x y))
  16. ; Setters
  17. (define-generic-function (setter elt)
  18. (thing index new-value))
  19. (define-method (setter elt) ((x <vector>) i z)
  20. (vector-set! x i z))
  21. ; (let ((v (vector 1 2 3))) (set (elt v 1) 'foo) v) => '#(1 foo 3)
  22. ; Classes
  23. (define-class <mumble> () a b)
  24. ; (a (make <mumble>)) => '*uninitialized*
  25. ; (let ((m (make <mumble>))) (set (a m) 'foo) (a m)) => 'foo
  26. (define-method initialize ((m <mumble>) z)
  27. (set (a m) z))
  28. ; (a (make <mumble> 3)) => 3