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

Stepper protocol



A quick definition: Steppers contain the current state of a loop
variable.  Steppers can be stepped through a sequence of values until
there are no more values.  The sequence could be all the elements in a
Table, all the Cardinal numbers, etc.  A loop might use several
Steppers, just like it might have many loop variables.  The loop
condition will typically conjunctively test all the Steppers for
termination.  Infinite Steppers always return true, of course.

here's a bunch of alternative names for the protocol:

1) The message which tests if there are any more values (ie whether
the stepper can be stepped):

hasValue(), hasMore(), isMore(), more(), notDone()

This message will typically control loops, so it returns true when
there are more values.  Thus:

while (tableStepper ->hasValue()) {...}

2) The message which returns the current value:

value(), iterand(), current(), get()/fetch()

3) The message which steps to the next state (unless there are no more
values):

step(), next(), nextValue()

I favor hasValue(), value(), and step().  The 'next' messages in place
of 'step' feel like the return values (Smalltalk bias).  Thus:

	for(Stepper * tableStepper = someTable ->stepper();
		tableStepper ->hasValue();
	    	tableStepper ->step) {
	    something(tableStepper ->value());
	}
or:
	tableStepper = someTable ->stepper();
	while (tableStepper ->hasValue()) {
	    something(tableStepper ->value());
	    tableStepper ->step();
	}

dean