mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
SRFI-1: Make `fold-right' tail-recursive.
* module/srfi/srfi-1.scm (fold-right): Make tail-recursive. * test-suite/tests/srfi-1.test ("fold-right"): New test prefix.
This commit is contained in:
parent
07076c1e61
commit
a6505cb49c
2 changed files with 34 additions and 8 deletions
|
@ -1266,6 +1266,28 @@
|
|||
(equal? '((1 2) (3 4) (5 6)) lst))))))
|
||||
|
||||
;;
|
||||
;; fold-right
|
||||
;;
|
||||
|
||||
(with-test-prefix "fold-right"
|
||||
|
||||
(pass-if "one list"
|
||||
(equal? (iota 10)
|
||||
(fold-right cons '() (iota 10))))
|
||||
|
||||
(pass-if "two lists"
|
||||
(equal? (zip (iota 10) (map integer->char (iota 10)))
|
||||
(fold-right (lambda (x y z)
|
||||
(cons (list x y) z))
|
||||
'()
|
||||
(iota 10)
|
||||
(map integer->char (iota 10)))))
|
||||
|
||||
(pass-if "tail-recursive"
|
||||
(= 1e6 (fold-right (lambda (x y) (+ 1 y))
|
||||
0
|
||||
(iota 1e6)))))
|
||||
;;
|
||||
;; unfold
|
||||
;;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue