Add define-method-star.
[8sync.git] / 8sync / systems / define-method-star.scm
1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
3 ;;;
4 ;;; This file is part of 8sync.
5 ;;;
6 ;;; 8sync is free software: you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation, either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; 8sync is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU Lesser General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with 8sync.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 (define-module (8sync define-method-star)
21   #:use-module (oop goops)
22   #:use-module (srfi srfi-1)
23   #:use-module (srfi srfi-11)
24   #:export (define-method*))
25
26 (define-syntax define-method*
27   (lambda (x)
28     (syntax-case x ()
29       ((_ (generic arg-spec ... . tail) body ...)
30        (let-values (((required-arg-specs other-arg-specs)
31                      (break (compose keyword? syntax->datum)
32                             #'(arg-spec ...))))
33          #`(define-method (generic #,@required-arg-specs . rest)
34              (apply (lambda* (#,@other-arg-specs . tail)
35                       body ...)
36                     rest)))))))