Skip to content

Instantly share code, notes, and snippets.

@panicz
Created April 21, 2017 21:18
Show Gist options
  • Save panicz/4b61cb44ffdbe19613e19f4f2579245f to your computer and use it in GitHub Desktop.
Save panicz/4b61cb44ffdbe19613e19f4f2579245f to your computer and use it in GitHub Desktop.
(define (passing-arguments arguments names final)
(assert (= (length arguments) (length names)))
(match arguments
(()
(assert (null? names))
final)
((argument . next)
(let (((name . names) names))
(if (compound? argument)
(passing-arguments next names
(passing argument
`(λ (,name) ,final)))
;else
(passing-arguments next names final))))))
(define (passing expression continuation)
(match expression
(('if <condition> <then> <else>)
(let ((result (original-name <condition>)))
(passing <condition> `(λ (,result)
(if ,result
,(passing <then> continuation)
,(passing <else> continuation))))))
((function . arguments)
(let ((simple-arguments (map (λ (argument)
(if (compound? argument)
(original-name argument)
argument))
arguments)))
(passing-arguments arguments simple-arguments
`(,(passing-function function)
,@simple-arguments
,continuation))))
(_ ;; value
`(,continuation ,expression))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment