old-define-method.scm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ;;; installed-scm-file
  2. ;;;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This library is free software; you can redistribute it and/or
  5. ;;;; modify it under the terms of the GNU Lesser General Public
  6. ;;;; License as published by the Free Software Foundation; either
  7. ;;;; version 2.1 of the License, or (at your option) any later version.
  8. ;;;;
  9. ;;;; This library is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;;; Lesser General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU Lesser General Public
  15. ;;;; License along with this library; if not, write to the Free Software
  16. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. ;;;;
  18. (define-module (oop goops old-define-method)
  19. :use-module (oop goops)
  20. :export (define-method)
  21. :no-backtrace
  22. )
  23. (define define-method
  24. (procedure->memoizing-macro
  25. (lambda (exp env)
  26. (let ((name (cadr exp)))
  27. (if (and (pair? name)
  28. (eq? (car name) 'setter)
  29. (pair? (cdr name))
  30. (symbol? (cadr name))
  31. (null? (cddr name)))
  32. (let ((name (cadr name)))
  33. (cond ((not (symbol? name))
  34. (goops-error "bad method name: ~S" name))
  35. ((defined? name env)
  36. `(begin
  37. ;; *fixme* Temporary hack for the current module system
  38. (if (not ,name)
  39. (define-accessor ,name))
  40. (add-method! (setter ,name) (method ,@(cddr exp)))))
  41. (else
  42. `(begin
  43. (define-accessor ,name)
  44. (add-method! (setter ,name) (method ,@(cddr exp)))))))
  45. (cond ((not (symbol? name))
  46. (goops-error "bad method name: ~S" name))
  47. ((defined? name env)
  48. `(begin
  49. ;; *fixme* Temporary hack for the current module system
  50. (if (not ,name)
  51. (define-generic ,name))
  52. (add-method! ,name (method ,@(cddr exp)))))
  53. (else
  54. `(begin
  55. (define-generic ,name)
  56. (add-method! ,name (method ,@(cddr exp)))))))))))