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

Support formatted string literals #1811

Closed
CodebyCR opened this issue Jul 28, 2022 · 8 comments
Closed

Support formatted string literals #1811

CodebyCR opened this issue Jul 28, 2022 · 8 comments
Labels
leads question A question for the leads team

Comments

@CodebyCR
Copy link

Why is the default #print function working in this why:

 var x = 7;
 Print("The value of x: {0} ", x)

Instated of the formatted Python string or the Swift print function:

In Python:

 var x = 7
 print(f"The value of x: {x} ")

In Swift:

 var x = 7;
 print("The value of x: \(x) ")

In my opinion this represents the future way, and is a lot more intuitive.
If there are no valid reasons for doing so, one should accept this adjustment.

My favoured solution is:

 var x = 7;
 Print("The value of x: {x} ")

and by default '{' and '}' must be masked by '\', if you want to see them in a string.

@jonmeow
Copy link
Contributor

jonmeow commented Jul 28, 2022

Duplicate of #1801

@jonmeow jonmeow marked this as a duplicate of #1801 Jul 28, 2022
@jonmeow jonmeow closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
@jonmeow jonmeow reopened this Jul 28, 2022
@jonmeow jonmeow changed the title Print with variables directly Support formatted string literals Jul 28, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Jul 28, 2022

Reading again, I think this is actually a question about formatted string literals, not Print. Retitled and moving to "questions for leads".

@Asaaj
Copy link

Asaaj commented Jul 29, 2022

This is called "string interpolation". Most languages require you to specify this explicitly (using a prefix symbol like $ in C# and f in Python, or a different string enclosing symbol like ` in javascript), though for the most part that has always seemed like a legacy compatibility problem to me. For interoperability and code-sharing between Carbon and C++, I'd guess we'd have to go the explicit route here, too.

@chandlerc
Copy link
Contributor

I'm generally very positive about string interpolation or f-strings etc.

However, I don't think this is a meaningful issue for leads at this point? We would need a proposal to consider actually adding them.

Maybe the question for leads is "are there any fundamental objections or concerns already known without a specific design that would make it not worthwhile to work on a proposal for adding formatted string literals or string interpolation features?"

I think the answer to that is "no", but will let other leads confirm.

(Generally, I also don't think it is necessary for folks to ask this as a question for leads before starting work on a proposal. More useful in my experience is to discuss it on Discord and the forums to collect any concerns the community might have and incorporate those into the eventual proposal.)

@zygoloid
Copy link
Contributor

zygoloid commented Aug 9, 2022

I agree with @chandlerc -- I see no concerns with adding this kind of feature, and it seems like useful functionality to support. We'll need to see a specific proposal that explores the design details in order to deliver useful feedback beyond that.

@chandlerc
Copy link
Contributor

I agree with @chandlerc -- I see no concerns with adding this kind of feature, and it seems like useful functionality to support. We'll need to see a specific proposal that explores the design details in order to deliver useful feedback beyond that.

Is it useful to keep an issue for leads here though? There doesn't seem to be anything for us to say "yes" or "no" or ... to?

@jonmeow jonmeow added the leads question A question for the leads team label Aug 10, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 12, 2022

Filed #2005 to track the need for a proposal in this space.

@chandlerc
Copy link
Contributor

Also closing the issue for now. We can always re-open it if some aspect of the proposal ends up having concerns or controversy.

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

No branches or pull requests

5 participants