From 73e7fd1df88999b02e89cd497e9baeb9a1a6bb40 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 29 Jul 2014 06:57:00 -0700 Subject: * eval.c (giterate_func, giterate): Adjusting semantics of giterate to include seed item in the sequence. The while test is applied to each item before it is passed through the function. Also, eliminated useless rplacd operation. * txr.1: Updated documentation of giterate. --- txr.1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 560f359f..e8da4242 100644 --- a/txr.1 +++ b/txr.1 @@ -9033,23 +9033,24 @@ the gen-func to populate it with the first item. The giterate function is similar to generate, except that and are functions of one argument rather than functions of no arguments. The optional argument defaults to nil and -is threaded through the function calls. Prior to producing the first item, -the lazy list returned by giterate invokes on . -If the call yields true, then is invoked on and the -resulting value is added to the sequence. That resulting value also becomes the -value for the next iteration: when is invoked again, that -value is used, rather than the original value. +is threaded through the function calls. That is to say, the lazy +list returned is ( [] [ [ ]] ...). + +The lazy list terminates when a value fails to satsify . +That is to say, prior to generating each value, the lazy list tests +the value using . If that function returns false, then +the item is not added, and the sequence terminates. Note: the giterate function could be written in terms of generate like this: (defun giterate (w g v) - (generate (lambda () [w v]) (lambda () (set v [g v])))) + (generate (lambda () [w v]) (lambda () (prog1 v (set v [g v]))))) .SS Example: - (giterate (op > 5) (op + 1) 0) -> (1 2 3 4 5) + (giterate (op > 5) (op + 1) 0) -> (0 1 2 3 4) .SS Function repeat -- cgit v1.2.3