[iterate-devel] critique of finding such-that on-failure clause
Hoehle, Joerg-Cyril
Joerg-Cyril.Hoehle at t-systems.com
Wed Nov 17 12:58:29 UTC 2004
Hi,
(iter(finding 1 such-that t on-failure (error "not found")))
does not do what one might expect. Neither does
(iter (finding 1 such-that t) (finally (error "not found")))
on-failure is a IMHO misnomer, because the argument is always evaluated. So it acts more like the third argument to gethash -- a default.
It's evaluated in the loop prologue. The manual does not say where on-failure is to be evaluated, but there's no easy way to move it to the epilogue because the manual states that the epilogue will be evaluated -- we'd need an extra flag to tell "in epilogue but not on successful finding".
As a result, finding such-that is rather different from
(if test (leave expr)) (finally (return on-failure-expr)
or
(thereis (funcall test expr)) (finally (return-on-failure-expr))
Well, I think that instead of changing the current behaviour (process or not the epilogue), it's better (for compatibility) to leave it as is and to show alternatives in the manual:
(thereis (evenp x)) (finally (error "not found")))
(if (evenp x) (leave x)) (finally (error "not found"))
Regards,
Jörg Höhle
More information about the iterate-devel
mailing list