Created
December 14, 2012 06:08
-
-
Save yao2030/4283063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (fold-left op initial sequence) | |
(define (iter result rest) | |
(if (null? rest) | |
result | |
(iter (op result (car rest)) | |
(cdr rest)))) | |
(iter initial sequence)) | |
(define fold-right accumulate) | |
(define (reverse seq) | |
(fold-right (lambda (x y) (append y (list x))) '() seq)) | |
(define (reverse seq) | |
(fold-left (lambda (x y) (cons y x)) '() seq)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment