From: Joe Marshall Date: Tue, 19 Jan 2016 18:13:06 +0000 (-0800) Subject: Remove REDUCE-LEFT from documentation. X-Git-Tag: mit-scheme-pucked-9.2.12~371^2~17 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5410eb4b2ef21d4b56cc08c1024f9df47c5c9328;p=mit-scheme.git Remove REDUCE-LEFT from documentation. --- diff --git a/doc/ref-manual/lists.texi b/doc/ref-manual/lists.texi index a4f77a662..a137de94f 100644 --- a/doc/ref-manual/lists.texi +++ b/doc/ref-manual/lists.texi @@ -1088,43 +1088,39 @@ is unspecified. @section Reduction of Lists @cindex reduction, of list -@deffn procedure reduce-left procedure initial list +@deffn procedure fold-left procedure initial list Combines all the elements of @var{list} using the binary operation -@var{procedure}. For example, using @code{+} one can add up all the -elements: - -@example -(reduce-left + 0 list-of-numbers) -@end example - -The argument @var{initial} is used only if @var{list} is empty; in this -case @var{initial} is the result of the call to @code{reduce-left}. If -@var{list} has a single argument, it is returned. Otherwise, the arguments -are reduced in a left-associative fashion. For example: +@var{procedure}. Elements are combined starting with @var{initial} and +then the elements of @var{list} from left to right. Whereas +@code{fold-right} is recursive in nature, capturing the essence of +@code{cdr}-ing down a list and then computing a result, @var{fold-left} +is iterative in nature, combining the elements as the list is traversed. @example @group -(reduce-left + 0 '(1 2 3 4)) @result{} 10 -(reduce-left + 0 '(1 2)) @result{} 3 -(reduce-left + 0 '(1)) @result{} 1 -(reduce-left + 0 '()) @result{} 0 -(reduce-left + 0 '(foo)) @result{} foo -(reduce-left list '() '(1 2 3 4)) @result{} (((1 2) 3) 4) +(fold-left list '() '(1 2 3 4)) @result{} ((((() 1) 2) 3) 4) + @end group @end example -@end deffn -@deffn procedure reduce-right procedure initial list -Like @code{reduce-left} except that it is right-associative. +Many of the classical list-processing +procedures can be expressed in terms of @code{fold-left}, at least for +the simple versions that take a fixed number of arguments: @example -(reduce-right list '() '(1 2 3 4)) @result{} (1 (2 (3 4))) +@group +(define (length list) + (fold-left (lambda (sum element) (+ sum 1)) 0 list)) + +(define (reverse items) + (fold-left (lambda (answer item) (cons item answer)) () items)) +@end group @end example @end deffn @deffn procedure fold-right procedure initial list Combines all of the elements of @var{list} using the binary operation -@var{procedure}. Unlike @code{reduce-left} and @code{reduce-right}, +@var{procedure}. Unlike @code{reduce} and @code{reduce-right}, @var{initial} is always used: @example @@ -1160,24 +1156,10 @@ the simple versions that take a fixed number of arguments: @end example @end deffn -@deffn procedure fold-left procedure initial list -Combines all the elements of @var{list} using the binary operation -@var{procedure}. Elements are combined starting with @var{initial} and -then the elements of @var{list} from left to right. Whereas -@code{fold-right} is recursive in nature, capturing the essence of -@code{cdr}-ing down a list and then computing a result, @var{fold-left} -is iterative in nature, combining the elements as the list is traversed. +@deffn procedure reduce-right procedure initial list @example -@group -(fold-left list '() '(1 2 3 4)) @result{} ((((() 1) 2) 3) 4) - -(define (length list) - (fold-left (lambda (sum element) (+ sum 1)) 0 list)) - -(define (reverse items) - (fold-left (lambda (x y) (cons y x)) () items)) -@end group +(reduce-right list '() '(1 2 3 4)) @result{} (1 (2 (3 4))) @end example @end deffn