| PasteRack.org | ||
| Paste # 11292 | ||
| 2019-11-22 14:52:39 | ||
Fork as a new paste. | ||
Paste viewed 535 times. | ||
Tweet | ||
Embed: | ||
;; define foldl using foldr
;; foldl-original : [X Y -> Y] Y [X] -> Y
(define (foldl-original f acc lst)
(cond
[(empty? lst) acc]
[(cons? lst)
(foldl f
(f (first lst) acc)
(rest lst))]))
;; define foldl using foldr
;; foldl^ : [X Y -> Y] Y [X] -> Y
(define (fold^ f acc ls) ...)
(check-expect (foldl^ + 0 (list 1 2 3 4 5)) 15)
(check-expect (foldl^ cons '() '(a b c)) '(c b a))