GNU bug report logs -
#24080
fold-left description in (rnrs lists) section of guile manual incorrect
Previous Next
Full log
View this message in rfc822 format
The section on the (rnrs lists) library in the guile manual contains the following:
Scheme Procedure: fold-left combine nil list1 list2 …
Scheme Procedure: fold-right combine nil list1 list2 …
These procedures are identical to the fold and fold-right procedures provided by SRFI-1.
In the case of fold-left and SRFI-1 fold, this is not correct; the order in which the arguments are passed to the combine procedure is different. Compare:
(let ((f (lambda (a b) (format #f "(f ~a ~a)" a b))))
(for-each
(lambda (fold)
(display (fold f "0" '(a b c d e)))
(format #t " ; ~s\n" (procedure-name fold)) )
(list (@ (rnrs lists) fold-left)
(@ (rnrs lists) fold-right) ;same as srfi-1 fold-right
(@ (srfi srfi-1) fold)
(@ (srfi srfi-1) fold-right))))
Output:
(f (f (f (f (f 0 a) b) c) d) e) ; fold-left
(f a (f b (f c (f d (f e 0))))) ; fold-right
(f e (f d (f c (f b (f a 0))))) ; fold
(f a (f b (f c (f d (f e 0))))) ; fold-right
In the single-list case, fold-left can be thought of as applying f left-associatively to the elements of the list.
Moreover, in this case (fold f nil l) == (fold-left (lambda (x y) (f y x)) nil l).
(In the case of fold-right, both versions are identical).
This bug report was last modified 9 years and 6 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.