Hacker News new | past | comments | ask | show | jobs | submit login
Why we created LFortran (lfortran.org)
12 points by johndcook on April 30, 2019 | hide | past | favorite | 8 comments

Almost all the cases under the “How to fix that” heading seem addressed by Julia, but also MATLAB or Python if performance is not an issue.

As a PhD student who heavily relies on highly optimized Fortran code and who has spent time translating small Fortran projects to Python+NumPy, I don’t understand why anyone would start a new project in Fortran. The only people I know who write Fortran do it because of legacy code or because that’s the only language they know.

Since calling Fortran is fairly well supported for languages used in/designed for science (Python, MATLAB, Julia), I don’t see legacy code being as big a driver.

One of LFortran authors here. You raised a good point. I would say for numerical computing, if performance is an issue, the best candidates are C++, Julia, Chapel and Fortran. Each has pros and cons, I am going to post a blog post about that, I didn't want to get into language comparison details in the announcement.

Bonus points for:

> Automatic transformation of code to older Fortran standard that other Fortran compilers can compile — allowing developers to use the latest standard, and still be able to use current Fortran compilers

Sometimes I have to make programs that run in machines nobody is sure about the configuration details.

Does it support "intersection format"? http://fortranwiki.org/fortran/show/Continuation+lines

Does it have a linter that can remove linenumbers in the easy cases?

> Does it support "intersection format"?

It doesn't yet. Are you interested in this for parsing or for code generation?

If for code generation (i.e., LFortran parses your Fortran code, and then generates a Fortran code back in this format), then I think that will not be that difficult to implement, I think this would be useful.

Regarding parsing, for now my parser is for free form. But I think it would be useful to also have a fixed form parser --- it might need to be a separate parser, but the rest of LFortran can be reused.

> Does it have a linter that can remove linenumbers in the easy cases?

Can you give an example of what you mean?

One issue with linting is that currently the parser is not round-trippable (https://gitlab.com/lfortran/lfortran/issues/42). That means that it can generate the original code back, but it will be formatted differently (mostly white space). Most compilers are not round-trippable. The only compiler that I know about that is round-trippable is C#. Essentially one has to keep track of white space and other formatting, and I didn't want this to complicate the internal representation. I wanted to design the internal representation that is as simple as possible. And then see if one can add optional nodes for white space, similarly how C# does it. If it's possible, then I'll do it.

However, even if it is not round-trippable, the linter can simply generate a nice Fortran code back, and if people use the linter like `clang-format`, enforced by the CI, then it might not be a problem.

Here is the current implementation of ASR (Abstract Semantic Representation) to AST (Abstract Semantic Tree):


And AST to source code:


We will be extending it this summer to support more Fortran features.

It's mostly about priority at this point --- I want all of the above to be implemented, it's just about what I do first and what second. Feel free to vote or open new issues here:


See also my current roadmap/priorities at the bottom of:


I suggested intersection format for the code generator part.

Also, there is a huge amount of legacy code flying around. Write the fixed form parser as soon as you can.

An example of legacy code with linenumbers is: (Extracted from real code, I only changed the variable names.)

        do 1 i = 1 , n
        do 1 j = 1 , n
          if(x(i,j).ne.y(I,j)) print*,x(i,j),y(j,i)
      1 continue

Regarding the fixed-form parser, I think that's a good idea. I just created an issue for it: https://gitlab.com/lfortran/lfortran/issues/82.

I see what you mean --- that's just a for loop. I created an issue for it: https://gitlab.com/lfortran/lfortran/issues/83.

Thanks for the feedback!

I've also seen weird controlflow using linenumbers, I pick an easy but common one. I don't expect that the program can handle all the cases and produce something sane. But most of the cases I saw are easily fixable with an enddo or endif.

I am one of the authors, I am happy to answer any questions.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact