Welcome to the CHICKEN Scheme pasting service
simple-generic added by dieggsy on Fri Jan 29 22:29:25 2021
(module simple-generic (define-generic
define-method)
(import scheme)
(import-for-syntax (only srfi-1 zip))
(define-syntax define-generic
(syntax-rules ()
((_ name)
(define (name . rest)
(import chicken.base)
(error "No matching methods for args" rest)))))
(define-syntax define-method
(er-macro-transformer
(lambda (x r c)
(let* ((name (caadr x))
(args (cdadr x))
(argnames (map cadr args))
(preds (map car args))
(body (cddr x)))
`(let ((old ,name))
(set! ,name
(lambda ,argnames
(if (and ,@(zip preds argnames))
(begin
,@body)
(old ,@argnames))))))))))