[J3] [EXTERNAL] Re: Re: Slides available for your preview - Part 2 of the Generics Tutorial today at the J3 plenary
Van Snyder
van.snyder at sbcglobal.net
Tue Mar 9 22:40:50 UTC 2021
On Tue, 2021-03-09 at 10:41 -0700, William Clodius via J3 wrote:
> Note that my additions to
> https://github.com/j3-fortran/generics/blob/main/Use_cases_and_requirements.md
> included some at least partial examples of containers.
In looking at that page, I noticed several instances of discussion of
iterators. There was a discussion of using DO WHILE as an iterator,
under the rubric "State of the art." But this does not preserve the
internal state of the iterator, unless it is maintained in a derived-
type object that is initialized by the "iterator" procedure, and the
using program unit is required to hold onto it, and pass it back into
the "iterator" for each iteration. This can be done, but it's a bit of
a mess:
Get a type definition from the module containing the "iterator"
Define an object STATE of the type (or several if several things are
being considered.
CALL ITERATOR_INIT ( STATE, ...)
do whIle ( ITERATING (STATE,...) )
blah, blah, blah
end while
Inside the iterator, there's typically a SELECT CASE construct that
implements a DFA. Before returning, the iterator sets its state
variable to indicate which case should be executed next. It's ugly.
An ITERATE construct, and an ITERATOR procedure would be easier to use,
and easier to write. Instead of having a SELECT CASE construct and a
state variable to indicate control flow, the iterator would have a
SUSPEND statement. When the iterator is resumed, by the ITERATE
statement of the ITERATE construct, control resumes after the SUSPEND
statement. When the iterator returns instead of suspending, the
construct terminates.
Coroutines and iterators use almost identical technology "under the
covers." The analogy I use is
Subroutine : Function :: Coroutine : Iterator
Coroutines and iterators are very old ideas. Coroutines are directly
supported in at least 48 other programming languages. They probably
appeared first in Simula 67. Iterators are directly supported in at
least ten other languages (including C++, C#, Java, and Python).
I wrote a proposal for coroutines and iterators (most recently in 2019,
and several earlier versions), but consideration of the topic was
repeatedly rejected, except for briefly being part of the F08 work plan
-- see 05-010r3.
It's attached, in case anybody is interested. The paper was posed in
the form of a TS, because it can be done that way -- unlike coarrays,
which have pervasive effects.
On the same page that Bill Clodius referenced, also under the rubric
"State of the art," was a lamentation that Fortran doesn't have
updaters. I also wrote about this, both as a "stand alone" concept (in
2010) and in the context of containers (in 2019). But consideration of
those concepts was rejected. Indeed, I proposed accessors at the 1986
X3J3 meeting in Albuquerque -- where the concept was rejected. Updaters
are also an old idea, dating back to at least POP-2 and MESA. Univac
FORTRAN V had a simple form of updater as a by-product of statement
functions having been implemented as macros, so references to them
could appear in variable-definition contexts, if their body was allowed
there. I used them to implement structures and dynamic memory.
Those proposals are attached too, in case anybody is interested.
In case the J3 mail server strips attachments, look at
http://vandyke.mynetgear.com/Fortran/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210309/a62af0a6/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Accessor-TR-6.pdf
Type: application/pdf
Size: 251404 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210309/a62af0a6/attachment-0003.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Container-TR-1.pdf
Type: application/pdf
Size: 254108 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210309/a62af0a6/attachment-0004.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Coroutines-TR-12.pdf
Type: application/pdf
Size: 223876 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210309/a62af0a6/attachment-0005.pdf>
More information about the J3
mailing list