[Grace-core] counting down with for loops?
Kim Bruce
kim at cs.pomona.edu
Tue Jul 1 14:00:02 PDT 2014
for loops are easy when you are counting up by 1: for (1..5) do {n -> print(n)}
Do we have operations that make it easy to count up by a number different from 1?
How about counting down?
I didn't see anything helpful in the current implementation of .. as lists. (I looked for a reverse method and couldn't find one -- perhaps that should be part of the list type.)
Do we care? I'd like to allow counting down, but don't care as much about counting by an increment.
I'm guessing that we don't care that there is no "do..while..." (guaranteeing execution of the loop body at least once). Advanced programmers can easily program their own:
method do(blk) while (cond) -> Done {
cond.apply
while(cond) do (blk)
}
Kim
More information about the Grace-core
mailing list