mark at timeandmotion.com.au
Wed Jun 20 08:55:54 CEST 2007
It strikes me that whilst it may not be the best programming form, the
same thing could be done readily with a global variable?
Tom Walsh wrote:
> Mark Wood wrote:
>>>> I have found that there are some functional differences that
>>>> Metaware has over
>>>> fpc, one example is the yield() function which returns the
>>>> intermediate result
>>>> of a function call.
>> '?' indeed! I am fascinated! What does yield do exactly... presumably
>> it returns a result from the function without closing down that
>> instance of the function? Amazing concept. I am still trying to work
>> out how that could be useful or even how it could be used (without
>> breaking stuff upstream).
> This would be one example, a function which returns a value each time
> it is called. There are some scoping rules which dictate whether the
> yield'ed function will init or continue from the last yield point:
> ============== begin ====================
> iterator LoopStep(Start, Stop, StepSize : StdInt) : StdInt;
> i, Answer, NumLoops : StdInt;
> if StepSize = 0 then return;
> Answer := Start;
> NumLoops := ((Stop - Start) DIV StepSize) + 1;
> for i := 1 to NumLoops do begin
> Answer := Answer + StepSize;
> ============== snip =====================
> Not sure why they found this terribly useful, but I don't write
> financial code...
More information about the fpc-pascal