On Sat, 2010-04-24 at 22:31 -0700, Richard Fateman wrote:
> instead of the keyword "do" you can use the keyword "collect", and
> the
> results will be returned in a list.
>
> for i:1 thru 4 collect i
>
> returns [1,2,3,4].
>
> Everything else that happens in the semantics of the "do loop" happens
> here as well, so you can
> count by non-integers, start and end at symbolic points so long as
> they differ by a number,
That's a very nice extension to the "do" loop. I suggest extending it
so that step can also be symbolic, as start and end, and not just a
number. Namely,
for i: c thru c+3 collect i
returns [c, c + 1, c + 2, c + 3]
But:
for i: c thru c+3*b step b collect i;
gives an error when it would be nice if it returned
[c, c + b, c + 2*b, c + 3*b]
That can be done as follows:
for var: start thru end step increment collect expr
1- evaluate n: float( (end - start)/increment ), which should give a
number.
2- initialize var: start, and an auxiliary integer index i: 0.
3- if i<n, substitute var in expr and push the result into the list; if
i>n, then end.
Regards,
Jaime