[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Stepper protocol



From: tribble (Eric Dean Tribble)
   ... I originally
   considered combining hasValue and step.  It unfortunately confuses the
   abstraction.  I expect to create a Stepper already set to its first
   value.  This is both cleaner and allows Steppers to be handed in to a
   function and used in the iteration.  I would also like Steppers to
   have the current value throughout each loop step.  Then they really
   are much more like loop variables.  I'm tempted though...

   dean

The way I did it was to have the loop initialized to "just before" the
first value so that the first Next() pulled the first value out of the
loop. It's not clear how this would fit into an abstraction that has
hasValue() and value() protocol -- maybe hasValue() would be false but
hasNext() would be true, and value() would be nil for a newly
initialized loop. The current value would remain the same through each
loop iteration though (i.e. they are pre-incrementing). This changes
the abstraction to be rather wierd unless you stick to just using
Next(); kind of like "p = a[-1]; while( x = *++p ) {...}"
	--ravi