define-module for elisp special modules
[bpt/guile.git] / module / ice-9 / match.scm
CommitLineData
d967913f
LC
1;;; -*- mode: scheme; coding: utf-8; -*-
2;;;
0a3ac81a 3;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
d967913f
LC
4;;;
5;;; This library is free software; you can redistribute it and/or
6;;; modify it under the terms of the GNU Lesser General Public
7;;; License as published by the Free Software Foundation; either
8;;; version 3 of the License, or (at your option) any later version.
9;;;
10;;; This library is distributed in the hope that it will be useful,
11;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;; Lesser General Public License for more details.
14;;;
15;;; You should have received a copy of the GNU Lesser General Public
16;;; License along with this library; if not, write to the Free Software
17;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c8762438 18
26d9bcd0 19(define-module (ice-9 match)
d967913f
LC
20 #:export (match
21 match-lambda
22 match-lambda*
23 match-let
24 match-let*
25 match-letrec))
c8762438 26
8d5d0425 27(define (error _ . args)
d967913f 28 ;; Error procedure for run-time "no matching pattern" errors.
8d5d0425 29 (apply throw 'match-error "match" args))
c8762438 30
5fcb7b3c
LC
31;; Support for record matching.
32
33(define-syntax slot-ref
34 (syntax-rules ()
35 ((_ rtd rec n)
36 (struct-ref rec n))))
37
38(define-syntax slot-set!
39 (syntax-rules ()
40 ((_ rtd rec n value)
41 (struct-set! rec n value))))
42
43(define-syntax is-a?
44 (syntax-rules ()
45 ((_ rec rtd)
46 (and (struct? rec)
47 (eq? (struct-vtable rec) rtd)))))
48
d967913f
LC
49;; Compared to Andrew K. Wright's `match', this one lacks `match-define',
50;; `match:error-control', `match:set-error-control', `match:error',
358663ca
LC
51;; `match:set-error', and all structure-related procedures. Also,
52;; `match' doesn't support clauses of the form `(pat => exp)'.
c8762438 53
d967913f 54;; Unmodified public domain code by Alex Shinn retrieved from
0a3ac81a 55;; the Chibi-Scheme repository, commit 1206:acd808700e91.
5fcb7b3c
LC
56;;
57;; Note: Make sure to update `match.test.upstream' when updating this
58;; file.
d967913f 59(include-from-path "ice-9/match.upstream.scm")