lfortran icon indicating copy to clipboard operation
lfortran copied to clipboard

Idea: Support dot (`.`) as an alternative to the `%` operator

Open certik opened this issue 3 years ago • 2 comments

Original issue: https://gitlab.com/lfortran/lfortran/-/issues/84

This is an idea to consider:

The . is a lot more readable, consider os.path.join() vs. os%path%join(). The reason it's more readable is because the . has more vertical space, and thus the words are visually more divided, while the % character is filling up all the space, and thus visually it is much harder to immediately see where one word ends and another begins.

Besides . being more readable, it is also way more common, e.g. in Python, C++, Julia and many other languages.

And Intel Fortran actually seems to support it in some cases.

It makes the parsing ambiguous, since a.not.b can be an operator .not., or derived type access. In addition, Fortran allows to have user defined operators, so any word of the type .something. can be an operator. However, there might be a way to parse things properly and to disambiguate this.

For example one way to do that would be that a.not.b would mean .not. as an operator. One should not use derived types with names like not. Regarding user defined operators, I would say user defined operators will take precedence, and so if one imports a user defined operator, say .path., then os.path.join() will mean .path. as an operator. One would need to use % in such a case then. This will be very rare, so shouldn't be a problem.

certik avatar Aug 15 '22 08:08 certik

Recent discussion at Discourse: https://fortran-lang.discourse.group/t/whats-your-experience-with-using-for-accessing-object-members/6642. The old discussion is at the original gitlab issue above, please read it in full before commenting here.

certik avatar Oct 16 '23 07:10 certik

If LFortran supports ., it can also automatically convert it to %, as requested, e.g., here: https://fortran-lang.discourse.group/t/changing-to-to-access-components-of-derived-types/8726

certik avatar Oct 18 '24 22:10 certik