case-warnings.scm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (case #\a
  2. ((1 2 3 4 5) '1to5)
  3. ((6 7 8 9 10) '6to10)
  4. (else (display 'else) (newline)))
  5. ;; Diagnostic: case-warnings.scm:2:5: warning - datum type (integer) incompatible with the key type (character)
  6. ;; Diagnostic: case-warnings.scm:2:7: warning - datum type (integer) incompatible with the key type (character)
  7. ;; Diagnostic: case-warnings.scm:2:9: warning - there are 8 more datums that are incompatible with the key
  8. ;; Output: else
  9. (format #t "~s~%" (case 10
  10. ((1 2 3) 10)
  11. ((4 5 6) 20)))
  12. ;; Diagnostic: case-warnings.scm:10:19: warning - missing else where value is required
  13. ;; Output: #!void
  14. (define (c x :: int)
  15. (case x
  16. ((10000000000) 3)
  17. (((2 3 4 5)) 'list)
  18. ((2 3 4 5) 'num)
  19. ((#\a) #\a)
  20. ((sym) 54)
  21. (("a") 'a)
  22. (else 3)))
  23. (display "list case: ")
  24. (display (c 5))
  25. (newline)
  26. ;; Diagnostic: case-warnings.scm:19:7: warning - List and vectors will never be matched in a case clause
  27. ;; Diagnostic: case-warnings.scm:19:7: warning - datum type (pair-with-position) incompatible with the key type (int)
  28. ;; Diagnostic: case-warnings.scm:21:7: warning - datum type (character) incompatible with the key type (int)
  29. ;; Diagnostic: case-warnings.scm:23:7: warning - a string in a case clause will never match (except another literal)
  30. ;; Diagnostic: case-warnings.scm:22:7: warning - there are 2 more datums that are incompatible with the key
  31. ;; Output: list case: num
  32. (define (d key)
  33. (case key
  34. ((1 2 3 4)
  35. (case key
  36. ((2 3 4) 3)
  37. ((1 5 6 7 8)
  38. (case key
  39. ((1 2 3 4) 1)
  40. ((5 6 7 8) 1)))))
  41. ((5 6 7 8) 1)
  42. ((9 10 11 12)
  43. (case key
  44. ((1 2 3 4)
  45. (case key
  46. ((1 2 3 4) 3)
  47. ((5 6 7 8)
  48. (case key
  49. ((1
  50. #(1 2 3 4)
  51. 3) 'vect)
  52. ((5 6 7 8) 1)))))))))
  53. (display "vector case: ")
  54. (display (d 5))
  55. (newline)
  56. ;; Diagnostic: case-warnings.scm:54:17: warning - List and vectors will never be matched in a case clause
  57. ;; Output: vector case: 1
  58. ;; key side effects
  59. (case (begin (display "side effect, ") 35)
  60. ((1 2 3 4 5) '1to5)
  61. ((6 7 8 9 10) '6to10)
  62. (else (display 'else) (newline)))
  63. ;; Output: side effect, else
  64. (define (tcase1 x)
  65. (case (begin (display "side effect, ") x)
  66. ((1 2 3 4 5) => (lambda (x) (format #t "c1 ~w~%" x)))
  67. ((6 7 8 9 10) '6to10)
  68. (else (display 'else) (newline))))
  69. (tcase1 4)
  70. ;; Output: side effect, c1 4
  71. (define (tcase2 x)
  72. (case (begin (display "side effect, ") x)
  73. ((1 2 3 4 5) (format #t "c1 ~w~%" x))
  74. ((6 7 8 9 10) '6to10)
  75. (else (display 'else) (newline))))
  76. (tcase2 4)
  77. ;; Output: side effect, c1 4