-
Notifications
You must be signed in to change notification settings - Fork 1
/
srfi-16.ss
22 lines (22 loc) · 1.06 KB
/
srfi-16.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(define-library (srfi 16)
(import (only (scheme r5rs) define-syntax syntax-rules lambda let length letrec-syntax error if = quote >= apply)
(only (srfi 23) error))
(export case-lambda)
(begin (define-syntax case-lambda
(syntax-rules ()
((case-lambda (params body0 ...) ...)
(lambda args
(let ((len (length args)))
(letrec-syntax
((cl (syntax-rules ::: ()
((cl)
(error "no matching clause"))
((cl ((p :::) . body) . rest)
(if (= len (length '(p :::)))
(apply (lambda (p :::) . body) args)
(cl . rest)))
((cl ((p ::: . tail) . body) . rest)
(if (>= len (length '(p :::)))
(apply (lambda (p ::: . tail) . body) args)
(cl . rest))))))
(cl (params body0 ...) ...)))))))))