j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Implement simpler print syntax: `print("Hello World!")` #335

Open certik opened 4 months ago

certik commented 4 months ago

Proposal: the syntax print("Hello World!") would be equivalent to print *, "Hello World!".

Advantages:

Disadvantages:

Discussed at:

certik commented 4 months ago

With j3-fortran/fortran_proposals#336, one could write:

character(:), allocatable :: s, text
integer :: i
real :: a
i=1
a=1.123456789
text="this"
s = f"{i} is an integer, {a:1.2f} is a rounded real and '{text}' is text"
print(s)

Or just:

character(:), allocatable :: text
integer :: i
real :: a
i=1
a=1.123456789
text="this"
print(f"{i} is an integer, {a:1.2f} is a rounded real and '{text}' is text")
klausler commented 4 months ago

This would obviously be ambiguous with current conforming and universally portable syntax.

character(20)::a='("hello")'
print(a)
end
certik commented 4 months ago

@klausler you are right, I forgot. I put a link to your example as the main disadvantage.

klausler commented 4 months ago

F'2023 notwithstanding, I think that it is a horrible thing to try to change the meanings of existing conforming portable programs. Please find another syntax or just stick with print *, ....

certik commented 4 months ago

@klausler I agree, I wasn't trying to change meaning to existing programs. I forgot that you can put parentheses after print, so I thought the parentheses would be enough to disambiguate it. Since this is conflicting with existing syntax, it seems it's not workable.

oxcrow commented 3 months ago

I find print *, "hello world" significantly easier to use (due to using Fortran for few years)

Although, I agree a simpler syntax maybe helpful to some newcomers.

So, yes, it could be a good addition to Fortran.

mjklemm commented 3 months ago

The part about having '{}' as format placeholder could be achieved by this: print '(Some value {}, another value {})', a, b. Still not Python syntax, but close.