and-let-star.scm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;;;; and-let-star.scm --- and-let* syntactic form (SRFI-2) for Guile
  2. ;;;;
  3. ;;;; Copyright (C) 1999, 2001, 2004, 2006, 2013 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (ice-9 and-let-star)
  19. :export-syntax (and-let*))
  20. (define-syntax %and-let*
  21. (lambda (form)
  22. (syntax-case form ()
  23. ((_ orig-form ())
  24. #'#t)
  25. ((_ orig-form () body bodies ...)
  26. #'(begin body bodies ...))
  27. ((_ orig-form ((var exp) c ...) body ...)
  28. (identifier? #'var)
  29. #'(let ((var exp))
  30. (and var (%and-let* orig-form (c ...) body ...))))
  31. ((_ orig-form ((exp) c ...) body ...)
  32. #'(and exp (%and-let* orig-form (c ...) body ...)))
  33. ((_ orig-form (var c ...) body ...)
  34. (identifier? #'var)
  35. #'(and var (%and-let* orig-form (c ...) body ...)))
  36. ((_ orig-form (bad-clause c ...) body ...)
  37. (syntax-violation 'and-let* "Bad clause" #'orig-form #'bad-clause)))))
  38. (define-syntax and-let*
  39. (lambda (form)
  40. (syntax-case form ()
  41. ((_ (c ...) body ...)
  42. #`(%and-let* #,form (c ...) body ...)))))
  43. (cond-expand-provide (current-module) '(srfi-2))