Skip to content

Add Interpolation Expression Sequences to the spec #3768

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

Merged
merged 5 commits into from
Feb 23, 2024

Conversation

schveiguy
Copy link
Member

@schveiguy schveiguy commented Feb 14, 2024

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @schveiguy!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@schveiguy schveiguy marked this pull request as draft February 14, 2024 05:07
@schveiguy schveiguy force-pushed the istring branch 2 times, most recently from b3668eb to 18be0b9 Compare February 14, 2024 21:14
@schveiguy schveiguy marked this pull request as ready for review February 15, 2024 04:35
@schveiguy
Copy link
Member Author

OK, I think this is ready for review. This needs to be merged before the next release.

"Interpolation Expression Sequence" is too long for the menu bar... Any ideas for an abbreviated name? Maybe just "Interpolations"?

@schveiguy schveiguy changed the title Add string interpolation to the spec Add Interpolation Expression Sequences to the spec Feb 15, 2024
@schveiguy
Copy link
Member Author

Unsure if adding this in where lexical goes (which I think is where it really belongs) is better than tacking on the end? Walter suggested here that the spec should be on its own page.

I dislike that I had to bump all chapters up by 1.

@schveiguy
Copy link
Member Author

ping, this should go in before the release candidate is branched.

@thewilsonator thewilsonator merged commit 67423cc into dlang:master Feb 23, 2024
Comment on lines +120 to +127
// simple version of std.typecons.Tuple
struct Tuple(T...) { T value; }
Tuple!T tuple(T...)(T value) { return Tuple!T(value); }

import core.interpolation;
string name = "John Doe";
auto items = tuple(i"Hello, $(name), how are you?");
assert(items == tuple(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the above lines can be simplified to:

alias AliasSeq(A...) = A;
import core.interpolation;
auto items = i"Hello, $(name), how are you?";
assert(items == AliasSeq!(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this works, I will simplify.

Copy link
Member Author

@schveiguy schveiguy Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... on second thought, this is doing something that I wasn't intending -- it's creating a compile-time sequence of things, including an alias to name. What I really wanted was to show that the sequence is the same at runtime, e.g. what the list of values is. So I think I will leave it as-is.

The Tuple type is needed because D doesn't let you return a value tuple directly.

@schveiguy schveiguy deleted the istring branch February 23, 2024 13:49
$(D iq{) $(GLINK InterpolatedTokenStringTokens)$(OPT) $(D })

$(GNAME InterpolatedTokenStringTokens):
$(GLINK InterpolatedTokenStringTokenNoBraces)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InterpolatedTokenStringTokenNoBraces is not defined. Here is a PR: #3772

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

Successfully merging this pull request may close these issues.

6 participants