Giter Site home page Giter Site logo

C-style formatting about stdlib HOT 9 OPEN

fortran-lang avatar fortran-lang commented on May 25, 2024
C-style formatting

from stdlib.

Comments (9)

marshallward avatar marshallward commented on May 25, 2024 4

Python 3 formatting is becoming quite widespread; I know that C# and Rust use them. It would be great to reach this point, but I agree with @cmacmackin that it might not be practical with Fortran syntax.

Those languages also offer C-style formatting, so I see no harm in pursuing both.

from stdlib.

longb avatar longb commented on May 25, 2024 3

Note that the Fortran 202X proposal list includes intrinsic functions for converting Fortran characters to C strings and vice versa.

from stdlib.

certik avatar certik commented on May 25, 2024 2

Perhaps using the Python 3 formatting syntax would work for Fortran: https://docs.python.org/3.1/library/string.html#format-specification-mini-language (see examples).

from stdlib.

cmacmackin avatar cmacmackin commented on May 25, 2024 1

A bit more thought makes me wonder if it would in fact be better to do this in Fortran, as converting between Fortran and C strings is quite a painful really.

Furthermore, some of the behaviour of printf is not exactly idiomatic for Fortran. In particular, Fortran does not have the concept of \t, \n, etc. within strings. Also, printing in Fortran would normally result in a new-line after, while this is not the default behaviour for printf (although it would be very easy to add a new-line). As such, it might be worth considering whether we want to define formatted printing that is specific to Fortran, perhaps using a syntax more like Python's format strings.

from stdlib.

14NGiestas avatar 14NGiestas commented on May 25, 2024 1

I agree with @gronki and I think this whole issue should migrate to a "string style formatting" type of discussion (For instance: #69 ) closing this one. We could implement some facility to convert a easier to write and read syntax to the standard way.
For example, take some sane string:

"My name is (A) and I want a readable spec, so I can show pi = (G0) and fruits = (I0) to my friends."

and convert to the weird and sometimes infuriating standard I/O

'("My name is ",A," and I want a readable spec, so I can show pi = ",G0," and fruits = ",I0," to my friends.")'

Then, finally using it as a sane format

write(f, sane_fmt) 'Ian', PI, my_fruits

Such facility would fit into a string module (like Python did, actually).

IDK, what you all think @certik @gronki @cmacmackin ?
PS: Related J3 proposal by gronki #69

from stdlib.

certik avatar certik commented on May 25, 2024

We can start with using C, and later we can perhaps reimplement in Fortran if we decide it is valuable to stay in pure Fortran (see #20).

from stdlib.

cmacmackin avatar cmacmackin commented on May 25, 2024

@certik Yes, that's what I was thinking of, although I don't think it would be practical to allow named-arguments in the format string, given Fortran doesn't have features like that.

from stdlib.

certik avatar certik commented on May 25, 2024

We can start without named arguments. Then go from there, perhaps there is a way to specify the names somehow, that is quite reasonable syntax-wise.

from stdlib.

gronki avatar gronki commented on May 25, 2024

I agree C-style formatting is already considered obsolete in Python. I would prefer just improving the currect capabilities of Fortran i/o.

On a side note, there has been recently a whole discussion whether "things easy to implement should be implemented or left for the programmer". My stand on this is "they should be implemented if they are the recommended way of doing things". Using C stdlib in Fortran is certainly not the purest way of doing things (and might possibly bring portability issues) so I would leave this burden and responsibility to the programmer.

What do you think?

from stdlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.