[fpc-pascal] Metaware

Tom Walsh tom at openhardware.net
Wed Jun 20 00:47:02 CEST 2007

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...


Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."

More information about the fpc-pascal mailing list