BANNER | ||
---|---|---|
Prev | Chapter 2 | Next |
(compose f1 f2) |
;; Make a function equivalent to applying `f2' to its arguments and ;; `f1' to the result. (define (compose f1 f2) (lambda (#!rest rest) (f1 (apply f2 rest)))) |
(curry f arg) |
;; Partially apply two-argument function `f' to `arg', returning a ;; one-argument function. (define (curry f arg) (lambda (a) (f arg a))) |
(curryn f rest) |
;; n-ary variant (define (curryn f #!rest rest) (lambda (#!rest args) (apply f (append rest args)))) |
(foldl f zero xs) |
;; Fold left with function `f' over list `xs' with the given `zero' ;; value. (Like DSSSL `reduce' but normal arg order.) (define (foldl f zero xs) (if (null? xs) zero (foldl f (f zero (car xs)) (cdr xs)))) |
(foldl1 f xs) |
;; Fold left with list car as zero. (define (foldl1 f xs) (cond ((null? xs) '()) ((null? (cdr xs)) (car xs)) (else (foldl f (car xs) (cdr xs))))) |
(foldr f zero xs) |
;; Fold right, as above. (define (foldr f zero xs) (if (null? xs) zero (f (car xs) (foldl f zero (cdr xs))))) |
Prev | Home | Next |
Flow Object | Up | Debugging |