1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
guile/test-suite/vm/t-match.scm
Ludovic Courtès 5fcb7b3cc5 Update (ice-9 match) from Chibi-Scheme.
* module/ice-9/match.scm (slot-ref, slot-set!, is-a?): New macros.

* module/ice-9/match.upstream.scm: Update from Chibi-Scheme.

* test-suite/Makefile.am (SCM_TESTS): Add `tests/match.test.upstream'.

* test-suite/tests/match.test (rtd-2-slots, rtd-3-slots): New record
  types.
  ("matches")["records"]: New test prefix.
  ("doesn't match")["records"]: New test prefix.
  Include `match.test.upstream'.

* test-suite/vm/t-match.scm (matches?): Fix `$' example.
2011-09-03 22:18:02 +02:00

26 lines
560 B
Scheme
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; Pattern matching with `(ice-9 match)'.
;;;
(use-modules (ice-9 match)
(srfi srfi-9)) ;; record type (FIXME: See `t-records.scm')
(define-record-type <stuff>
(%make-stuff chbouib)
stuff?
(chbouib stuff:chbouib stuff:set-chbouib!))
(define (matches? obj)
; (format #t "matches? ~a~%" obj)
(match obj
(($ <stuff>) #t)
; (blurps #t)
("hello" #t)
(else #f)))
;(format #t "go!~%")
(and (matches? (%make-stuff 12))
(matches? (%make-stuff 7))
(matches? "hello")
; (matches? 'blurps)
(not (matches? 66)))