Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2a9dba2f9e
Fetching contributors…

Cannot retrieve contributors at this time

33 lines (26 sloc) 0.693 kb
;; Example 2.39
(define (fold-right op initial seq)
(if (null? seq)
initial
(op (car seq)
(fold-right op initial (cdr seq)))))
;(fold-right + 0 (list 1 2 3 4 5))
(define (fold-left op initial seq)
(define (iter result rest)
(if (null? rest)
result
(iter (op result (car rest))
(cdr rest))))
(iter initial seq))
(define (reverse-1 seq)
(fold-right (lambda (x y)
(append y (list x)))
null
seq))
(reverse-1 (list 1 2 3 4 5))
(define (reverse-2 seq)
(fold-left (lambda (x y)
(append (list y) x))
null
seq))
(reverse-2 (list 1 2 3 4 5 6))
Jump to Line
Something went wrong with that request. Please try again.