Comments (9)
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.
Note that the Fortran 202X proposal list includes intrinsic functions for converting Fortran characters to C strings and vice versa.
from stdlib.
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.
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.
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.
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.
@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.
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.
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)
- `bits()` in `bitset_type` returned a non-zero value even though no value is set. HOT 1
- Support for linear algebra HOT 6
- Hashtable write error on exit HOT 7
- use stdlib_math, only : gcd HOT 4
- The file src/stdlib_hashmap_chaining.f90 and two others are set as executable HOT 1
- Support for I/O of standard formats HOT 10
- Memory mapped features HOT 9
- Add `.gitignore` to `stdlib-fpm` deployment for generated test files HOT 1
- hash_functions test fails on i386: `Segmentation fault - invalid memory reference`
- Request to upgrade Intel-classic compiler in macOS CI
- Add `library` configuration to `stdlib-fpm`
- Massive slow down in docs generation HOT 4
- Unexpected performance of hash maps HOT 8
- python preprocessor HOT 11
- add topic tags `lapack`, `blas`, `linear-algebra` HOT 1
- Improve descriptions of rotm, rotmg, stdlib_srotm, stdlib_srotmg
- Don't repeat names of procedures in descriptions
- stdlib_io_npy, FPM and Rank > 4 HOT 5
- Missing documentation for `LAPACK`-related functions HOT 6
- Adding the logarithmic derivative of the gamma function (digamma) to stdlib_specialfunctions_gamma HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stdlib.