-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
non-interpolating string literal syntax? #11764
Comments
The best option is to have all string literal syntax be non-interpolating. Simple :) |
Interpolatio delenda est. |
Yes, that's a severe problem with the current interpolation syntax, which I'd love to see deprecated. |
Realistically, the current interpolation syntax is not going anywhere. There seem to be no other people who find the |
In fact as soon as you need parens the value of interpolation goes down significantly. Interpolation works best when "just a $variable" is interpolated. I suspect most people prefer |
Jeff, c'mon man, you had the chance to get rid of this a couple years ago and didn't do it. Let's not rehash this. I get it, you don't like interpolation. Let's focus on the issue at hand, which is not whether to get rid of interpolation in normal string literals or change its syntax. I guess I should have known better than to open this issue. |
I'm just saying that
I don't think that's a very accurate description. |
We had horse traded this at some point (back when we could still do that). I agreed to getting rid of interpolation in exchange for something or other. I think the plan was juxtaposition instead. |
Yes, we were considering |
@JeffBezanson It's no extra characters at all, for the @StefanKarpinski I can't find it right now, but a lot of people have been complaining about string interpolation, and would like to at least have non-interpolated strings, that would be more compatible with |
The UNIX shells started the whole interpolation with The reason using |
I thought that |
The cost of putting in a backslash hardly seems worth another string literal type/macro. You also have to escape " so it's not that surprising... An alternative solution, for the most common problem, is for strings like "$10" to be allowed to parse since what follows the $ is not an identifier. |
Seems a bit too brittle. Currently it's whatever expression comes after, which is pretty simple. |
@hayd The problem is simply that since the string formats are almost identical, people copy strings from C/C++/Java/JSON directly into their programs... and then end up with bugs, and have to go through line by line to find the cases of |
Composing the different kinds of string literals is a significant problem; e.g. if you want a utf-16 string without interpolation. It starts to get ugly. |
I wouldn't want interpolation for any of them... what people were asking for was to have C/C++/Java like strings, and not have to worry about |
No argument there :) |
How's about allowing either identifier or digits. e.g. "$10a" would fail but "$10.00" would work (similar to "$a.00" works now). This seems to cover the most common cases without breaking any existing code. Edit, to clarify:
|
I'm not a fan of '''You've won $1,000,000 (not interpolated)''' mostly because that starts to cloud the syntax (it's too close to Why not go back to a (And for what it's worth, I do rather like string interpolation--thanks for defending it Stefan!) |
For me |
I meant to say this before: if we go with a macro, how's about: |
I kind of like |
We used to have |
I'd like to have a raw, but also have another that is just |
I'm with @ScottPJones, |
IMO raw should have no interpolation, innocuous or otherwise. I think the one tricky bit/ambiguity is backlash escapes e.g. |
yeah, I shouldn't have said "raw", I should have said "just |
Yes, I'd like a raw, but what I said was I wanted another one, that was closer to C/C++/Java/Swift/JSON... u"This is a string with funny Unicode characters, like \⊕ it costs $10, and it also can handle 0x\(hex(mychar))" |
@yuyichao, in PyPlot you can use |
@stevengj That trick only helps people using PyPlot though, in the specific case of LaTex labels, correct? |
Maybe you should deprecate interpolation on |
Yes, that's only for the PyPlot/LaTex use-case mentioned above. Having to escape I feel like the ship has sailed here on radical changes to interpolation syntax. A macro is a good option, but there is the question of whether it should still make backslash substitutions (by default, a string macro will treat backslashes as literal chars); it seems like one could get a large number of different "raw" string macro variants depending on the data source, and I'm not clear on what should be in Base... |
What if we used suffixes to customize the kind of raw string you want? Something like raw"..." escapes both |
I think that's reasonable. Most of the time, people would just use On Saturday, July 11, 2015, Jonathan Malmaud notifications@github.com
|
In the context of avoiding disruption of existing code, raw"..." sounds good, as long as there is a solution for "you won $$(prize)" case. |
Any chance
|
It's true that string interpolation is currently the most concise way to do... string interpolation. I have grown to love this feature, except when it presents you with unhelpful line numbers in error messages. Here is a ~220 line We do need a non-interpolating string literal syntax. The |
I'm not too concerned about needing literal |
Our docstrings are already reasonably smart about interpolation and escaping, so it's not that awful. julia> x = "bar"
"bar"
julia> md"""
foo $x baz
$\sqrt{x^2 + y^2}$
"""
foo bar baz
\sqrt{x^2 + y^2} |
Could the docstrings be smart enough to also parse
as LaTeX and not as
I can't find a satisfactory workaround. |
That should work without the spaces between the |
Thanks, that could work. In case it is any push to extend the syntax a bit, the demo at http://pandoc.org/try/ parses both of these:
as LaTeX, but does not parse this as LaTeX:
|
If we do this, we should use |
Using |
@hayd, |
See also this thread for some relevant discussion. |
Just stumbled across this issue and thought I'd add a slight correction to the list of other languages interpolation syntaxes. Ruby can use Obviously the situation is not completely analogous with Julia since Ruby's short-hand interpolation syntax doesn't work with local variables. In the comments on that issue, though, there's a very good analysis that even when the short-hand could have been used, it largely wasn't. Removing the short-hand interpolation syntax seems to be the simplest solution to the issues presented here, and Ruby's experience seems to indicate that it wouldn't be horribly missed in the long term. |
close given the raw string macro from #19900? |
It's come up pretty regularly that having a non-interpolating string literal syntax would be handy. Maybe
Whether to do indentation stripping or not would be an open question.
The text was updated successfully, but these errors were encountered: