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));
var
I: 1..MaxSize;
begin
for I := 1 to aDirectory.Size do
with aDirectory.Entry[i] do
Yield(Name, Number);
end;
end;
{ 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.
TomW
--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------------------------------------------
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal