-
-
Save leque/9293286 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 use-env) | |
`(cut% () () ,@(cdr form))))) | |
(define-syntax cut% | |
(sc-macro-transformer | |
(lambda (form env) | |
(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 slots)) | |
(combi (cons x combi))) | |
`(cut% ,slots ,combi ,@(cdr se))))) | |
(else | |
(let ((slots slots) | |
(combi (cons (make-syntactic-closure env '() (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