Last active
December 31, 2015 06:59
-
-
Save ktakashi/7951362 to your computer and use it in GitHub Desktop.
innerっぽい何か
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (rnrs) (clos user) (clos core)) | |
(define-class <generic-inner> (<generic>) ()) | |
(define-method compute-applicable-methods ((gf <generic-inner>) args) | |
`(,@(reverse! (call-next-method)) | |
;; add very bottom one | |
,(make-method (list <top>) | |
(lambda (call-next-method o) "")))) | |
(define-generic inner :class <generic-inner>) | |
(define-method inner (o) (call-next-method)) | |
(define-class <document> () ()) | |
(define-class <report> (<document>) ()) | |
(define-class <combine> (<report>) ()) | |
(define-method inner ((o <document>)) | |
(string-append "<doc>" | |
(call-next-method) | |
"</doc>")) | |
(define-method inner ((o <report>)) | |
(string-append "<title>foo</title>" | |
"<summary>bar</summary>" | |
"<body>" | |
(call-next-method) | |
"</body>")) | |
(define-method inner ((o <combine>)) "hello") | |
(define (xml o) (inner o)) | |
(print (xml (make <document>))) | |
;; -> <doc></doc> | |
(print (xml (make <report>))) | |
;; -> <doc><title>foo</title><summary>bar</summary><body></body></doc> | |
(print (xml (make <combine>))) | |
;; -> <doc><title>foo</title><summary>bar</summary><body>hello</body></doc> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment