Last active
August 29, 2015 13:56
-
-
Save stibear/9290489 to your computer and use it in GitHub Desktop.
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 cut% | |
(sc-macro-transformer | |
(lambda (form env) | |
(letrec ((map-msc | |
(lambda (x) | |
(map (lambda (ex) | |
(make-syntactic-closure env '(<> <...>) ex)) | |
x)))) | |
(let ((slots (cadr form)) | |
(combi (caddr form)) | |
(se (cdddr form))) | |
(cond ((null? se) | |
(let ((slots (reverse slots)) | |
(combi (reverse combi))) | |
`(lambda ,slots ((begin ,(car combi)) ,@(cdr combi))))) | |
((eq? (car se) '<...>) | |
(let ((slots (fold-right cons | |
'rest-slot | |
(reverse slots))) | |
(combi (reverse (cons 'rest-slot combi)))) | |
`(lambda ,slots (apply ,@combi)))) | |
((eq? (car se) '<>) | |
(let ((x (make-syntactic-closure env '() 'x))) | |
(let ((slots (cons x (map-msc slots))) | |
(combi (cons x (map-msc combi)))) | |
`(cut% ,slots ,combi ,@(cdr se))))) | |
(else | |
(let ((slots (map-msc slots)) | |
(combi (map-msc (cons (car se) combi)))) | |
`(cut% ,slots ,combi ,@(cdr se)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment