[iterate-devel] Between-each

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Fri Dec 2 17:56:00 UTC 2005


Hi,

Mészáros Levente wrote:
>I may be wrong about this, but I could not find support for a 
>quite commonly used loop pattern, namely when you want 
>something to be evaluated between each loop cycles.

Please accept my apology for responding that late. I felt a little uncomfortable (see below) and did not quite know how to reply.

>(def-special-clause BETWEEN-EACH (between)
>  (return-code :body (list (if-1st-time nil (list (walk-expr between))))))
Correct code (like implementation of IF-FIRST-TIME).

>Maybe I'm wrong, could somebody tell how to do this with 
>iterate? If there's no support for this perhaps you could put 
>something like this into the main branch.
You could use a macro-substitution and expand to the exported and documented IF-FIRST-TIME and DEFMACRO-CLAUSE, instead of using package internals like return-code.


Your implementation shows that there's the same relationship between IF-FIRST-TIME and your BETWEEN-EACH like there's between WHEN and UNLESS.

So why not add it, even it would be redundant to purists?
However, given that analogy, I find the given name quite misleading, as it's very different from AFTER-EACH.

>And it works like:
>(iter (for i from 1 to 3) (between-each (collect (+ i 100))) 
>  (collect i))
>(1 102 2 103 3)
Hmm, I feel uncomfortable with the name, given the functionality you show. "Between" is something I'd expect to happen after one iteration, while you use it within the body. I.e., my wording shows I'm thinking in terms of AFTER-EACH.

Well, there's AFTER-EACH, which is subject to code movement, but wouldn't it work for you?

Another question is: how does this extension behave when used outside the top-level of the loop. Does the given name adequately reflect the functionality?

E.g. (iter (for i...) (if (oddp i) (between-each (collect i))))
What would a reader expect as value from such a form?
What about BUT-FIRST[-TIME] as a name?

Would you like to show more elaborate loop examples?

Regards,
	Jörg Höhle.



More information about the iterate-devel mailing list