[iterate-devel] thereis vs. collect ?

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Wed May 31 08:03:57 UTC 2006


Chris Dean writes:
>I'm getting an error when using thereis and collect in the 
>same iterate:
>  (iter (for x :in '(3 1 4 1 5 9))
>        (thereis (evenp x))
>        (collect x)))
This is ill-defined.  Thinking about signatures and/or functional programming helps to understand what matches and what doesn't.
COLLECT means that the value is a list type.
THEREIS means that the value is some element type.
These are not combinable.
What would be a proper type declaration for the result variable?

THEREIS is combinable with ALWAYS, NEVER, IF-EXISTS: the generalized boolean finders.
COLLECT is combinable with APPENDING, UNIONING etc.

>I can rewrite it to bypass thereis:
LEAVE bypasses every accumulation, so it always works.

>or use my own accumulation variable:
Indeed, the conflict only arises when collecting into the same variable: either the default one, as in (COLLECT x), or sharing an explicit one, as in (COLLECT x INTO y).

>  (iter (for x :in '(3 1 4 1 5 9))
>        (thereis x)
>        (collect x :into y)))
collect/y is ignored here. Did you forget (FINALLY (return y))?
I'm not sure that the documentation clearly specifies when the epilogue is bypassed and when not.  The above FINALLY only makes sense if THEREIS exists without running the epilogue in case of success.  The implementation is like this, but one should only depend on it if its documented.

I've had plans to fix specification holes in the documentation, add summarizing tables, but no time so far.  Documentation patches are welcome.

Regards,
	Jorg Hohle.



More information about the iterate-devel mailing list