chibi-scheme/lib/srfi/16.sld
Alex Shinn bd32131b9d The big renaming to define-library in .sld, make it possible to pass
other version numbers than 7 to `scheme-report-environment`, providing
initial (scheme base) library.
2011-10-02 17:16:05 +09:00

23 lines
865 B
Scheme

(define-library (srfi 16)
(export case-lambda)
(import (scheme))
(begin
(define-syntax %case
(syntax-rules ()
((%case args len n p ((params ...) . body) . rest)
(if (= len (length '(params ...)))
(apply (lambda (params ...) . body) args)
(%case args len 0 () . rest)))
((%case args len n (p ...) ((x . y) . body) . rest)
(%case args len (+ n 1) (p ... x) (y . body) . rest))
((%case args len n (p ...) (y . body) . rest)
(if (>= len n)
(apply (lambda (p ... y) . body) args)
(%case args len 0 () . rest)))
((%case args len n p)
(error "case-lambda: no cases matched"))))
(define-syntax case-lambda
(syntax-rules ()
((case-lambda . clauses)
(lambda args (let ((len (length args))) (%case args len 0 () . clauses))))))))