Skip to content

Instantly share code, notes, and snippets.

@omegatakuma
Created March 20, 2012 10:25
Show Gist options
  • Save omegatakuma/2133920 to your computer and use it in GitHub Desktop.
Save omegatakuma/2133920 to your computer and use it in GitHub Desktop.
[Scheme]CPS
;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