Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping numbers with spaces in free form #311

Open
tkoenig1 opened this issue Aug 5, 2023 · 6 comments
Open

Grouping numbers with spaces in free form #311

tkoenig1 opened this issue Aug 5, 2023 · 6 comments

Comments

@tkoenig1
Copy link

tkoenig1 commented Aug 5, 2023

There are two advantages of fixed form: First, it makes it possible to write

      PROGRAMME MAIN

for those who prefer British spelling, and it offers the possibility of
grouping numbers, like

      MILLION = 1 000 000

The first advantage is not really big, but the second one is actually a serious use case when trying not to lose count of digits.

So, a syntax to allow grouping of numbers would come in handy. Other languages have underscores, but that is already taken in Fortran for KIND. But what about actually allowing spaces in free form in numbers?

@FortranFan
Copy link
Member

@tkoenig1 wrote Aug. 5, 2023 5:53 PM EDT:

a syntax to allow grouping of numbers would come in handy

It will be great if you @tkoenig1 can draft a proposal in the J3 paper format and post it here:
https://j3-fortran.org/doc/meeting/231

These are the kind of proposals toward which WG5 must show vision to address and open up a "lane" for fast and easy discussion and ready acceptance into the Fortran standard. One should not have to wait 5 to 10 years.

@septcolor
Copy link

septcolor commented Aug 11, 2023

For namelist files, it has different interpretations for arrays?

program main
    implicit none
    integer :: arr(3), inp
    namelist /param/ arr

    open(newunit=inp, file="param.dat", status="old")
    arr(:) = 0
    read(inp, nml=param)
    print *, arr(:)       !! 1  200  0
    close(inp)
end

!! param.dat
&param
arr = 1 200 000

  !! (The above line is the same as)
  !! arr = 1, 200, 000
  !! arr(1:3) = 1, 200, 000
/

Using double underscores (like 1__000__000) or tilde (like 1~000~000) might be another approach (cf: Concatenation of arrays and strings in the D language below)

@ivan-pi
Copy link

ivan-pi commented Sep 24, 2023

This would've been handy for me in the past, when copying routines from Julia.

@FortranFan
Copy link
Member

This would've been handy for me in the past, when copying routines from Julia.

Are you implying some corollary to the jaded disclaimer, "past performance is no guarantee of future results"!!!?

Since"(t)his would've been handy for" you "in the past", can a reader see this as useful in the future too? or not?!

@ivan-pi
Copy link

ivan-pi commented Sep 24, 2023

Sorry I was unclear. I once did a porting of the Julia's erfinv function, which contains grouped numbers:

        return x * @horner(t, 0.16030_49558_44066_229311e2,
                             -0.90784_95926_29603_26650e2,
                              0.18644_91486_16209_87391e3,
                             -0.16900_14273_46423_82420e3,
                              0.65454_66284_79448_7048e2,
                             -0.86421_30115_87247_794e1,
                              0.17605_87821_39059_0) /

The grouping absolutely helps guide the eye when entering digits by hand, and it would save me the effort of deleting the underscores. I'd appreciate having it in the future.

Python allows grouping digits too:

$ python3
Python 3.10.9 (main, Jan 11 2023, 09:18:20) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.000_10_3_4
1.0001034

Using a different symbol than _ would however introduce friction for people used to Python or Julia.

@tkoenig1
Copy link
Author

Using a different symbol than _ would however introduce friction for people used to Python or Julia.

One could argue that Python and Julia introduced the friction by deviating from Fortran's prior use of _ :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants