Steve Yegge's rant on The Next Big Language

BCS ao at pathlink.com
Tue Feb 13 17:00:34 PST 2007


Reply to Frits,

> BCS wrote:
> 
>> Reply to Jarrett,
>> 
>>> Generators, on the other hand, are just plain cool.  I think they
>>> can be done using something like StackThreads.
>>> 
>> I'm missing somthing here: what is a generator?
>> 
> A generator is like a function, but after it "returns" it can be
> "called" again and it will resume where it left off. Local variables
> are
> preserved, and execution resumes after the statement that caused the
> return.
> They're basically an automated method for creating an iterator object
> out of an opApply-like function.
> In Python, you create them by using 'yield' instead of return. Python
> tutorial section on generators:
> http://docs.python.org/tut/node11.html#SECTION00111000000000000000000
> 

I should be burned at the stake for this...

| struct
| {
|   // all needed variables
|   int at=0;
|   
|   int go() // fn with no local variables
|   {
|     switch(at)
|     {
|       case -1:
|       assert(false);
| 
|       case 0:
| 
|       //stuff
| 
|      at=1; return value; case 1:
| 
|       // more stuff
| 
|       at=2; return value; case 2:
| 
|       // more stuff
| 
|     }
|     at = -1;
|     return value;
|   }
| }





More information about the Digitalmars-d-announce mailing list