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. --- eval.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index e44d132f..1c9724cd 100644 --- a/eval.c +++ b/eval.c @@ -3160,12 +3160,9 @@ val generate(val while_pred, val gen_fun) static val giterate_func(val env, val lcons) { cons_bind (while_pred, gen_fun, env); - val value = lcons->lc.car; + val next_item = funcall1(gen_fun, lcons->lc.car); - if (!funcall1(while_pred, value)) { - rplacd(lcons, nil); - } else { - val next_item = funcall1(gen_fun, value); + if (funcall1(while_pred, next_item)) { val lcons_next = make_lazy_cons(lcons_fun(lcons)); rplacd(lcons, lcons_next); rplaca(lcons_next, next_item); @@ -3180,9 +3177,8 @@ static val giterate(val while_pred, val gen_fun, val init_val) if (!funcall1(while_pred, init_val)) { return nil; } else { - val first_item = funcall1(gen_fun, init_val); val lc = make_lazy_cons(func_f1(cons(while_pred, gen_fun), giterate_func)); - rplaca(lc, first_item); + rplaca(lc, init_val); return lc; } } -- cgit v1.2.3