Fortran function remembers values (newbie help)

I thought about how to fix this (and many other such issues) immediately, not in 10 or 20 years or after we retire.

I think the best way to do it is like TypeScript fixed JavaScript. My understanding of how they did it is by:

  • First writing a compiler that understands all of current JavaScript
  • Extending the compiler to support types and other nice features that they determined they want to have.
  • Compiling all these extensions into standard JavaScript, so that existing JavaScript interpreters (i.e. browsers) can work with it
  • Working with the wider JavaScript community to get some of the nicest features into JavaScript itself

I would like to use a similar approach with LFortran. Please help me brainstorm it how it can work.

  • First write a regular compiler that supports all of current Fortran (we are well on the way)
  • Extend the compiler (initially enabled with an optional flag) with whatever we want to get fixed. We can start with:
    • Reclaim the natural syntax integer :: x = 5 for initializing the integer, not the save
    • implicit none is removed and on all the time
  • LFortran can either compile this as usual, or one can use LFortran to transpile into a subset of standard Fortran that works today with all Fortran compilers

Just like we decided to use a fancy preprocessor for stdlib, which makes stdlib completely not directly compilable with any Fortran compiler, but rather it depends on a single tool to transpile stdlib into standard Fortran. And we are fine with it (I certainly am!). We use the transpiled version in release tarballs, with fpm, etc. And yet we cannot contribute back directly to the transpiled version. One has to go into the git version which requires the fypp preprocessor.

So exactly in the same way, I can imagine having projects using these extensions and just use the LFortran tool to transpile into standard Fortran. Conceptually it is I think equivalent to stdlib + fypp. As well as to TypeScript + JavaScript.

2 Likes