t-match.scm 560 B

123456789101112131415161718192021222324252627
  1. ;;; Pattern matching with `(ice-9 match)'.
  2. ;;;
  3. (use-modules (ice-9 match)
  4. (srfi srfi-9)) ;; record type (FIXME: See `t-records.scm')
  5. (define-record-type <stuff>
  6. (%make-stuff chbouib)
  7. stuff?
  8. (chbouib stuff:chbouib stuff:set-chbouib!))
  9. (define (matches? obj)
  10. ; (format #t "matches? ~a~%" obj)
  11. (match obj
  12. (($ <stuff>) #t)
  13. ; (blurps #t)
  14. ("hello" #t)
  15. (else #f)))
  16. ;(format #t "go!~%")
  17. (and (matches? (%make-stuff 12))
  18. (matches? (%make-stuff 7))
  19. (matches? "hello")
  20. ; (matches? 'blurps)
  21. (not (matches? 66)))