srfi-11.scm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ; Copyright (C) Lars T Hansen (1999). All Rights Reserved.
  2. ; Permission is hereby granted, free of charge, to any person
  3. ; obtaining a copy of this software and associated documentation files
  4. ; (the "Software"), to deal in the Software without restriction,
  5. ; including without limitation the rights to use, copy, modify, merge,
  6. ; publish, distribute, sublicense, and/or sell copies of the Software,
  7. ; and to permit persons to whom the Software is furnished to do so,
  8. ; subject to the following conditions:
  9. ; The above copyright notice and this permission notice shall be
  10. ; included in all copies or substantial portions of the Software.
  11. ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12. ; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13. ; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. ; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  15. ; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. ; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. ; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. ; SOFTWARE.
  19. ; Taken directly from the SRFI document.
  20. (define-syntax let-values
  21. (syntax-rules ()
  22. ((let-values (?binding ...) ?body0 ?body1 ...)
  23. (let-values "bind" (?binding ...) () (begin ?body0 ?body1 ...)))
  24. ((let-values "bind" () ?tmps ?body)
  25. (let ?tmps ?body))
  26. ((let-values "bind" ((?b0 ?e0) ?binding ...) ?tmps ?body)
  27. (let-values "mktmp" ?b0 ?e0 () (?binding ...) ?tmps ?body))
  28. ((let-values "mktmp" () ?e0 ?args ?bindings ?tmps ?body)
  29. (call-with-values
  30. (lambda () ?e0)
  31. (lambda ?args
  32. (let-values "bind" ?bindings ?tmps ?body))))
  33. ((let-values "mktmp" (?a . ?b) ?e0 (?arg ...) ?bindings (?tmp ...) ?body)
  34. (let-values "mktmp" ?b ?e0 (?arg ... x) ?bindings (?tmp ... (?a x)) ?body))
  35. ((let-values "mktmp" ?a ?e0 (?arg ...) ?bindings (?tmp ...) ?body)
  36. (call-with-values
  37. (lambda () ?e0)
  38. (lambda (?arg ... . x)
  39. (let-values "bind" ?bindings (?tmp ... (?a x)) ?body))))))
  40. (define-syntax let*-values
  41. (syntax-rules ()
  42. ((let*-values () ?body0 ?body1 ...)
  43. (begin ?body0 ?body1 ...))
  44. ((let*-values (?binding0 ?binding1 ...) ?body0 ?body1 ...)
  45. (let-values (?binding0)
  46. (let*-values (?binding1 ...) ?body0 ?body1 ...)))))