Files
picrin/contrib/10.optional/piclib/optional.scm
T
OGINO Masanori ed86a8e28d Add (picrin optional).
The library provides some macros to handle optional arguments. The
macros are compatible with those in Chicken, Gauche, etc.

Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-09-22 23:44:58 +09:00

25 lines
652 B
Scheme

(define-library (picrin optional)
(import (scheme base))
(define-syntax optional
(syntax-rules ()
((_ args default)
(let ((t args))
(if (null? t) default (car t))))))
(define-syntax let-optionals*
(syntax-rules ()
((_ args () body ...)
(begin body ...))
((_ args ((var default) . tail) body ...)
(let* ((t args)
(var (if (null? t) default (car t)))
(remain (if (null? t) '() (cdr t))))
(let-optionals* remain tail body ...)))
((_ args rest body ...)
(let ((rest args))
body ...))))
(export optional
let-optionals*))