Created
April 27, 2020 15:18
-
-
Save edw/dfd03d7ccd3f65a9056ff84a40f170cf to your computer and use it in GitHub Desktop.
Scheme `let-optionally`
This file contains 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
(define-syntax let-optionally | |
(syntax-rules (_) | |
((_ vs () e f ...) | |
(let () e f ...)) | |
((_ vs (_ xv ...) e f ...) | |
(if (null? vs) | |
(let-optionally '() (xv ...) e f ...) | |
(let-optionally (cdr vs) (xv ...) e f ...))) | |
((_ vs ((x v) xv ...) e f ...) | |
(if (null? vs) | |
(let ((x v)) | |
(let-optionally '() (xv ...) e f ...)) | |
(let ((x (car vs))) | |
(let-optionally (cdr vs) (xv ...) e f ...)))))) | |
(import (chibi test)) | |
(test-begin "LET-OPTIONALLY") | |
(test '(0 1 3 4) | |
(let-optionally '(0 1 2 3 4 5) | |
((x #f) (y #f) _ (z #f) (w #f) _ _ _) | |
(list x y z w))) | |
(test-end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment