I want to know how to transform a let expression to continuation passing style like this:
(let ([a (lambda (x) (+ 1 x))]) (a 4))
Please show me some examples.Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, note that the
letis macro-expanded to the following:So, now, let’s CPS-transform the above, and we get:
where the
kon the final line is the continuation your originalletuses.If all those
ks look too confusing, here’s the same code:where the
k0is the original continuation.In both cases, I assume that
+is also similarly CPS-transformed to take a continuation to pass the result of the addition to….