87.sld 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;;; Copyright (C) 2006 Chongkai Zhu. All Rights Reserved.
  2. ;;; Made an R7RS library by Taylan Ulrich Bayırlı/Kammer, Copyright (C) 2014.
  3. ;;; Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ;;; of this software and associated documentation files (the "Software"), to
  5. ;;; deal in the Software without restriction, including without limitation the
  6. ;;; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. ;;; sell copies of the Software, and to permit persons to whom the Software is
  8. ;;; furnished to do so, subject to the following conditions:
  9. ;;; The above copyright notice and this permission notice shall be included in
  10. ;;; all copies or substantial portions of the Software.
  11. ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. ;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. ;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. ;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. ;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. ;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  17. ;;; IN THE SOFTWARE.
  18. (define-library (srfi 87)
  19. (export case)
  20. (import (except (scheme base) case))
  21. (begin
  22. (define-syntax case
  23. (syntax-rules (else =>)
  24. ((case (key ...)
  25. clauses ...)
  26. (let ((atom-key (key ...)))
  27. (case atom-key clauses ...)))
  28. ((case key
  29. (else => result))
  30. (result key))
  31. ((case key
  32. ((atoms ...) => result))
  33. (if (memv key '(atoms ...))
  34. (result key)))
  35. ((case key
  36. ((atoms ...) => result)
  37. clause clauses ...)
  38. (if (memv key '(atoms ...))
  39. (result key)
  40. (case key clause clauses ...)))
  41. ((case key
  42. (else result1 result2 ...))
  43. (begin result1 result2 ...))
  44. ((case key
  45. ((atoms ...) result1 result2 ...))
  46. (if (memv key '(atoms ...))
  47. (begin result1 result2 ...)))
  48. ((case key
  49. ((atoms ...) result1 result2 ...)
  50. clause clauses ...)
  51. (if (memv key '(atoms ...))
  52. (begin result1 result2 ...)
  53. (case key clause clauses ...)))))))