Created
February 10, 2010 11:50
-
-
Save valvallow/300235 to your computer and use it in GitHub Desktop.
sum 1 to 10
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
(define fact | |
(lambda (n) | |
(if (zero? n) | |
1 | |
(* n (fact (- n 1)))))) | |
(fact 5) | |
;; apply | |
(use srfi-1) | |
(define fact | |
(lambda (n) | |
(apply * (iota n 1)))) | |
(fact 5) | |
;; fold | |
(use srfi-1) | |
(define fact | |
(lambda (n) | |
(fold * 1 (iota n 1)))) | |
(fact 10) | |
; -> fold | |
;; cps | |
(define fact/cps | |
(lambda (n cont) | |
(if (zero? n) | |
(cont 1) | |
(fact/cps (- n 1)(lambda (x) | |
(cont (* x n))))))) | |
(fact/cps 5 (lambda (x) x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment