Created
March 20, 2012 10:25
-
-
Save omegatakuma/2133920 to your computer and use it in GitHub Desktop.
[Scheme]CPS
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
;default | |
(define (fact lst) | |
(if (null? (cdr lst)) | |
(car lst) | |
(begin | |
(print lst) | |
(* (car lst) (fact (cdr lst)))))) | |
;CPS | |
(define (fact/cps lst cont) | |
(cond | |
((null? lst) '()) | |
((zero? (car lst)) (cont 0)) | |
((not (null? (cdr lst))) | |
(begin | |
(print lst) | |
(* (car lst) (fact/cps (cdr lst) cont)))) | |
(else (car lst)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment