Skip to content

Instantly share code, notes, and snippets.

@leque
Forked from stibear/cut-sc-ver.scm
Last active August 29, 2015 13:56
Show Gist options
  • Save leque/9293286 to your computer and use it in GitHub Desktop.
Save leque/9293286 to your computer and use it in GitHub Desktop.
(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