curried-definitions.scm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; Copyright (C) 2010, 2013 Free Software Foundation, Inc.
  2. ;;;
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. (define-module (ice-9 curried-definitions)
  17. #:replace ((cdefine . define)
  18. (cdefine* . define*)
  19. define-public
  20. define*-public))
  21. (define-syntax make-currying-define
  22. (syntax-rules ::: ()
  23. ((_ currying-name lambda-name)
  24. (define-syntax currying-name
  25. (lambda (St-Ax)
  26. (syntax-case St-Ax ()
  27. ((_ ((head2 . rest2) . rest) docstring body body* ...)
  28. (string? (syntax->datum #'docstring))
  29. ;; Keep moving docstring to outermost lambda.
  30. #'(currying-name (head2 . rest2)
  31. docstring
  32. (lambda-name rest body body* ...)))
  33. ((_ (head . rest) body body* ...)
  34. #'(currying-name head
  35. (lambda-name rest body body* ...)))
  36. ((_ name val)
  37. #'(define name val))))))))
  38. (make-currying-define cdefine lambda)
  39. (make-currying-define cdefine* lambda*)
  40. (define-syntax make-currying-define-public
  41. (syntax-rules ::: ()
  42. ((_ public-name define-name)
  43. (define-syntax public-name
  44. (lambda (St-Ax)
  45. (syntax-case St-Ax ()
  46. ((_ binding body body* ...)
  47. #`(begin
  48. (define-name binding body body* ...)
  49. (export #,(let find-name ((form #'binding))
  50. (syntax-case form ()
  51. ((head . tail)
  52. (find-name #'head))
  53. (name
  54. #'name))))))))))))
  55. (make-currying-define-public define-public cdefine)
  56. (make-currying-define-public define*-public cdefine*)