[fpc-pascal] Metaware

Tom Walsh tom at openhardware.net
Wed Jun 20 01:13:44 CEST 2007

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:

About three years ago, when this project was first proposed, I did find 
a white-paper written by someone at Metaware which outlined the 
internals of the yield().  Apparently, they construct a seperate stack 
frame for a function containing a yield().  When it is first called via 
the main entry point, it constructs the frame and fills the local vars.  
Subsequent calls cause the function to be continued, rather than run 
from the initial entry point.  This is an example from the manual:

============ begin ==============
Package Telephone_directories;
iterator AllEntriesInOrder (const aDirectory: Directory) :
       (const NextName: string(10); const NextNumber: string(8));
    I: 1..MaxSize;
    for I := 1 to aDirectory.Size do
       with aDirectory.Entry[i] do
          Yield(Name, Number);

{ this is a new program that uses the iterator }
    with Telephone_Directories;   { with seems to be something like the 
'uses' clause }
    var MyDirectory: Directory;
    for aName, aNumber in AllEntriesInOrder(MyDirectory) do
       writeln (aName, ' : ', aNumber);

================ snip ===================

Oh, then there is the "cycle" statement which reads very much like the 
continue statement we all know about....

Odd shi^H^Htuff.


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