Coroutines in C

Peter da Silva peter at ficc.uu.net
Wed Aug 16 23:36:27 AEST 1989


Generators in 'C'... I guess you could use coroutines to implement
something like Icon generators, but Smalltalk generators might be
easier. There's more to Icon generators than the function itself...
how do you do !every write(factor(192))!?

Generators in Smalltalk are implemented differently than in Icon.
You set up methods for getting the first and next element of the
sequence, and use instance variables (if necessary) to maintain
state. This is more conventional, and wouldn't require coroutines.

	gen = NewGenerator(Factor);
	x = gen->First(192);
	while(x) {
		Write(x);
		x = gen->Next();
	}

This is a job (removes glasses, or is that classes?) for C++?
-- 
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.
Business: peter at ficc.uu.net, +1 713 274 5180. | "The sentence I am now
Personal: peter at sugar.hackercorp.com.   `-_-' |  writing is the sentence
Quote: Have you hugged your wolf today?  'U`  |  you are now reading"



More information about the Comp.lang.c mailing list