From 341ac57c0bcbdc31571ec0d63c63803d502c5a4a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 14 Feb 2012 01:34:44 -0800 Subject: * eval.c (rangev_func): Improved termination test. The sequence not only if it achieves the endpoint, but if it crosses it. --- ChangeLog | 5 +++++ eval.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 138afbce..64c9605f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-02-14 Kaz Kylheku + + * eval.c (rangev_func): Improved termination test. The sequence + not only if it achieves the endpoint, but if it crosses it. + 2012-02-13 Kaz Kylheku * eval.c (dwim_loc): Allow assignment to the dwim place when it diff --git a/eval.c b/eval.c index b3f62189..1454d43d 100644 --- a/eval.c +++ b/eval.c @@ -1666,19 +1666,22 @@ static val rangev_func(val env, val lcons) { cons_bind (from, to_step, env); cons_bind (to, step, to_step); + val next = if3(functionp(step), + funcall1(step, from), + plus(step, from)); rplaca(lcons, from); - if (equal(from, to)) { + if (eql(from, to) || + (lt(from, to) && gt(next, to)) || + (gt(from, to) && lt(next, to))) + { rplacd(lcons, nil); return nil; } - if (functionp(step)) - rplaca(env, funcall1(step, from)); - else - rplaca(env, plus(from, step)); rplacd(lcons, make_lazy_cons(lcons_fun(lcons))); + rplaca(env, next); return nil; } -- cgit v1.2.3