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

Overloading of concatenation and assignment operators for character variables #341

Open
awvwgk opened this issue Mar 13, 2021 · 0 comments
Labels
idea Proposition of an idea and opening an issue to discuss it topic: strings String processing

Comments

@awvwgk
Copy link
Member

awvwgk commented Mar 13, 2021

Additionally to the basic character manipulation in stdlib_ascii and the stdlib_string_type we might want to allow for a somewhat looser and less strict string handling.

The idea would be to overload common string operators like // to allow concatenating with implicit conversion to character values.

Originally posted by @urbanjost in #336 (comment):

I find overloading helps make things much more compact, so assuming you have a function like STR, overloading // with that allows you to do things like "MESSAGE='the value is '//10//' and the limit is '//300.4//'.'". Some would probably like to overload + to do that, but I prefer to overload + - / * to convert strings to numbers, and to overload INT(), REAL(), and DBLE() to take character values and assume they are numeric. So that makes for a symmetric set for converting to and from strings and numeric values.

Originally posted by @ivan-pi in #336 (comment):

Both Java and Javascript support the idiom of using the concatenation operator to build a string using

String s = "" + i;

If operator(//) were overload then one could do the same thing in Fortran:

character(len=:), allocatable :: s
s = ''//42   ! or 42//''

Similarly, one could think about overloading the assignment operator for such purposes, at the risk of running into the usual fixed length vs. deferred length character issues.

@awvwgk awvwgk added topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... idea Proposition of an idea and opening an issue to discuss it labels Mar 13, 2021
@awvwgk awvwgk added topic: strings String processing and removed topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... labels Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it topic: strings String processing
Projects
None yet
Development

No branches or pull requests

1 participant