Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!wuarchive!texbell!sugar!ficc!peter
From: peter@ficc.uu.net (Peter da Silva)
Newsgroups: comp.lang.c
Subject: Re: Coroutines in C
Message-ID: <5710@ficc.uu.net>
Date: 16 Aug 89 13:36:27 GMT
References: <5663@ficc.uu.net> <14281@haddock.ima.isc.com> <563@augean.OZ> <10097@csli.Stanford.EDU>
Organization: Xenix Support, FICC
Lines: 23

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@ficc.uu.net, +1 713 274 5180. | "The sentence I am now
Personal: peter@sugar.hackercorp.com.   `-_-' |  writing is the sentence
Quote: Have you hugged your wolf today?  'U`  |  you are now reading"