[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 14/87: define-generic, define-extended-generic are hygie
From: |
Andy Wingo |
Subject: |
[Guile-commits] 14/87: define-generic, define-extended-generic are hygienic syntax |
Date: |
Thu, 22 Jan 2015 17:29:45 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 2db04836c9423690db31a299d4e2687d74149ad6
Author: Andy Wingo <address@hidden>
Date: Sun Jan 4 15:35:25 2015 -0500
define-generic, define-extended-generic are hygienic syntax
* module/oop/goops.scm (define-generic, define-extended-generic):
(define-extended-generics): Reimplement using syntax-case.
---
module/oop/goops.scm | 55 ++++++++++++++++++++++++++++---------------------
1 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 000294e..15bbf95 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -732,30 +732,37 @@
;; Apparently the desired semantics are that we extend previous
;; procedural definitions, but that if `name' was already a generic, we
;; overwrite its definition.
-(define-macro (define-generic name)
- (if (not (symbol? name))
- (goops-error "bad generic function name: ~S" name))
- `(define ,name
- (if (and (defined? ',name) (is-a? ,name <generic>))
- (make <generic> #:name ',name)
- (ensure-generic (if (defined? ',name) ,name #f) ',name))))
-
-(define-macro (define-extended-generic name val)
- (if (not (symbol? name))
- (goops-error "bad generic function name: ~S" name))
- `(define ,name (make-extended-generic ,val ',name)))
-
-(define-macro (define-extended-generics names . args)
- (let ((prefixes (get-keyword #:prefix args #f)))
- (if prefixes
- `(begin
- ,@(map (lambda (name)
- `(define-extended-generic ,name
- (list ,@(map (lambda (prefix)
- (symbol-append prefix name))
- prefixes))))
- names))
- (goops-error "no prefixes supplied"))))
+(define-syntax define-generic
+ (lambda (x)
+ (syntax-case x ()
+ ((define-generic name) (symbol? (syntax->datum #'name))
+ #'(define name
+ (if (and (defined? 'name) (is-a? name <generic>))
+ (make <generic> #:name 'name)
+ (ensure-generic (if (defined? 'name) name #f) 'name)))))))
+
+(define-syntax define-extended-generic
+ (lambda (x)
+ (syntax-case x ()
+ ((define-extended-generic name val) (symbol? (syntax->datum #'name))
+ #'(define name (make-extended-generic val 'name))))))
+
+(define-syntax define-extended-generics
+ (lambda (x)
+ (define (id-append ctx a b)
+ (datum->syntax ctx (symbol-append (syntax->datum a) (syntax->datum b))))
+ (syntax-case x ()
+ ((define-extended-generic (name ...) #:prefix (prefix ...))
+ (and (and-map symbol? (syntax->datum #'(name ...)))
+ (and-map symbol? (syntax->datum #'(prefix ...))))
+ (with-syntax ((((val ...)) (map (lambda (name)
+ (map (lambda (prefix)
+ (id-append name prefix name))
+ #'(prefix ...)))
+ #'(name ...))))
+ #'(begin
+ (define-extended-generic name (list val ...))
+ ...))))))
(define* (make-generic #:optional name)
(make <generic> #:name name))
- [Guile-commits] 07/87: %init-goops-builtins is an extension, not a global, (continued)
- [Guile-commits] 07/87: %init-goops-builtins is an extension, not a global, Andy Wingo, 2015/01/22
- [Guile-commits] 03/87: Rewrite %method-more-specific? to be in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 10/87: Remove declarations without definitions, Andy Wingo, 2015/01/22
- [Guile-commits] 08/87: Preparation for more GOOPS refactorings, Andy Wingo, 2015/01/22
- [Guile-commits] 09/87: Remove unused %fast-slot-ref / %fast-slot-set! from GOOPS, Andy Wingo, 2015/01/22
- [Guile-commits] 02/87: Deprecate C interfaces scm_compute_applicable_methods, scm_find_method, Andy Wingo, 2015/01/22
- [Guile-commits] 12/87: Deprecate scm_basic_make_class, Andy Wingo, 2015/01/22
- [Guile-commits] 04/87: Remove unused macros in goops.c, Andy Wingo, 2015/01/22
- [Guile-commits] 06/87: compute-cpl implementation only in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 13/87: `class' is a hygienic macro, Andy Wingo, 2015/01/22
- [Guile-commits] 14/87: define-generic, define-extended-generic are hygienic syntax,
Andy Wingo <=
- [Guile-commits] 15/87: Remove unused *goops-module* definition., Andy Wingo, 2015/01/22
- [Guile-commits] 17/87: Remove unused scm_t_method and SCM_METHOD, Andy Wingo, 2015/01/22
- [Guile-commits] 20/87: Remove useless scm_s_slot_set_x export, Andy Wingo, 2015/01/22
- [Guile-commits] 18/87: Deprecate scm_no_applicable_method C export, Andy Wingo, 2015/01/22
- [Guile-commits] 21/87: Remove unused `default-slot-definition-class' <class> slot, Andy Wingo, 2015/01/22
- [Guile-commits] 22/87: Remove unused CPP defines naming <method> slots, Andy Wingo, 2015/01/22
- [Guile-commits] 19/87: Remove unreachable code in scm_setter, Andy Wingo, 2015/01/22
- [Guile-commits] 26/87: Remove scm_at_assert_bound_ref, Andy Wingo, 2015/01/22
- [Guile-commits] 25/87: Remove hashset slots from GOOPS classes, Andy Wingo, 2015/01/22
- [Guile-commits] 29/87: More unused code removal in GOOPS, Andy Wingo, 2015/01/22