[Grace-core] counting down with for loops?

Andrew P. Black black at cs.pdx.edu
Tue Jul 1 15:10:25 PDT 2014


Already done: please look at collections!

at present, you can say aRange.from(1)to(5).reversed, or aRange.from(5)downTo(1)

	Andrew

On 1 Jul 2014, at 14:00, Kim Bruce <kim at cs.pomona.edu> wrote:

> 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.)
> 

There are no reverse, or reversed, methods on lists at present.   Would you like them?   (reverse would mutate the current object; reversed would create a new object).  

> 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).  

More generally, do we seek completeness in our suite of provided methods, or adequacy?  I like the rich set of methods provide by Smalltalk, for example, but simplicity would argue for a minimal set of methods.   Perhaps different sets in different preludes (beginning Grace would’ve a minimal set, other dialects could have more.)

	Andrew

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140701/87e3c518/attachment.html>


More information about the Grace-core mailing list