diff options
author | Mark H Weaver <mhw@netris.org> | 2011-12-30 23:26:32 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2011-12-30 23:26:32 -0500 |
commit | 2f50d0a89758894a39bcec5a94c658d63d20701b (patch) | |
tree | ba297de980bb39736d3d8c4a9e232e90a921cd64 | |
parent | 3004fe262401f87aa92e24ec69115d9269c0df99 (diff) | |
download | guile-2f50d0a89758894a39bcec5a94c658d63d20701b.tar.gz |
Fix documentation for vhash-fold and vhash-fold-right
* doc/ref/api-compound.texi (VHashes): Add missing `init' parameter in
documentation for vhash-fold and vhash-fold-right, and also improve
description.
* module/ice-9/vlist.scm (vhash-fold, vhash-fold-right): Rename formal
parameter `seed' to `init', to match documentation. Improve
docstrings.
-rw-r--r-- | doc/ref/api-compound.texi | 11 | ||||
-rw-r--r-- | module/ice-9/vlist.scm | 21 |
2 files changed, 19 insertions, 13 deletions
diff --git a/doc/ref/api-compound.texi b/doc/ref/api-compound.texi index c52fed42c..da8ca9199 100644 --- a/doc/ref/api-compound.texi +++ b/doc/ref/api-compound.texi @@ -3293,10 +3293,13 @@ Again the choice of @var{hash-proc} must be consistent with previous calls to @code{vhash-cons}. @end deffn -@deffn {Scheme Procedure} vhash-fold proc vhash -@deffnx {Scheme Procedure} vhash-fold-right proc vhash -Fold over the key/value elements of @var{vhash} in the given direction. -For each pair call @var{proc} as @code{(@var{proc} key value result)}. +@deffn {Scheme Procedure} vhash-fold proc init vhash +@deffnx {Scheme Procedure} vhash-fold-right proc init vhash +Fold over the key/value elements of @var{vhash} in the given direction, +with each call to @var{proc} having the form @code{(@var{proc} key value +result)}, where @var{result} is the result of the previous call to +@var{proc} and @var{init} the value of @var{result} for the first call +to @var{proc}. @end deffn @deffn {Scheme Procedure} vhash-fold* proc init key vhash [equal? [hash]] diff --git a/module/ice-9/vlist.scm b/module/ice-9/vlist.scm index 8c7c87b72..a62bf59f2 100644 --- a/module/ice-9/vlist.scm +++ b/module/ice-9/vlist.scm @@ -545,23 +545,26 @@ with @var{equal?}." (define vhash-delq (cut vhash-delete <> <> eq? hashq)) (define vhash-delv (cut vhash-delete <> <> eqv? hashv)) -(define (vhash-fold proc seed vhash) - "Fold over the key/pair elements of @var{vhash}. For each pair call -@var{proc} as @code{(@var{proc} key value result)}." +(define (vhash-fold proc init vhash) + "Fold over the key/pair elements of @var{vhash} from left to right, with +each call to @var{proc} having the form @code{(@var{proc} key value result)}, +where @var{result} is the result of the previous call to @var{proc} and +@var{init} the value of @var{result} for the first call to @var{proc}." (vlist-fold (lambda (key+value result) (proc (car key+value) (cdr key+value) result)) - seed + init vhash)) -(define (vhash-fold-right proc seed vhash) - "Fold over the key/pair elements of @var{vhash}, starting from the 0th -element. For each pair call @var{proc} as @code{(@var{proc} key value -result)}." +(define (vhash-fold-right proc init vhash) + "Fold over the key/pair elements of @var{vhash} from right to left, with +each call to @var{proc} having the form @code{(@var{proc} key value result)}, +where @var{result} is the result of the previous call to @var{proc} and +@var{init} the value of @var{result} for the first call to @var{proc}." (vlist-fold-right (lambda (key+value result) (proc (car key+value) (cdr key+value) result)) - seed + init vhash)) (define* (alist->vhash alist #:optional (hash hash)) |