Skip to content

Instantly share code, notes, and snippets.

@imphasing
Created November 7, 2011 17:40
Show Gist options
  • Save imphasing/1345626 to your computer and use it in GitHub Desktop.
Save imphasing/1345626 to your computer and use it in GitHub Desktop.
(define-rewriter do
(lambda (form rename)
(let ((bindings (map (lambda (x) (cons (car x) (list (cadr x)))) (cadr form)))
(steps (map (lambda (x) (if (< 2 (length x)) (caddr x) (car x))) (cadr form)))
(condition (car (car (cddr form))))
(endresult (cadr (car (cddr form))))
(expr (cdddr form))
(loop-name (gensym)))
`(,(rename 'let) ,loop-name ,bindings
(,(rename 'if) (,(rename 'not) ,condition)
(,(rename 'begin) ,@expr ,(cons loop-name steps))
,endresult)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment