mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
* 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.
26 lines
560 B
Scheme
26 lines
560 B
Scheme
;;; 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)))
|