-
-
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
indented multiline strings using """ ... """ #70
Comments
Why do we have two issues for multiline quotes? I like ###. I think it is a good idea to not introduce a new symbol for quotes. Perhaps, some of the rules can be applied though. |
This is for strings, not comments. |
There were accidentally two identical issues opened for this, but I think Viral is talking about the one for comments vs. this one which is for strings. Having a real multiline string syntax is really handy, which is why all of Perl, Python and Ruby have them. It's not essential, however, which is why this is a v2.0 issue. I just wanted to get some thoughts down regarding the matter while I had them on my mind. |
I think it would be nice if comments and strings could be handled similarly. I could see cases where comments could be meta data for downstream tools. Regardless, http://en.wikipedia.org/wiki/Here_document (multi-line strings) is a huge huge win for
Java and C really got this wrong. |
Multiline strings can be with version 2. I like {: :} ( it looks like Julia to me. ) |
Have I missed something? Multiline strings work fine now as long as you escape inner quotes. While not having to do that would be nice, I think the title here might be a bit confusing on that point. |
My ignorance -- everything I had seen was written in a way that suggested multi-line strings were not available. |
@pao, multiline strings work fine, but they're not ideal for including text in indented code. That's what my proposal for |
@StefanKarpinski Understood; I think the bug title isn't quite clear based on Jeffrey's question, not that this isn't a good idea. I just haven't figured out what to retitle it to, or I'd have just changed it. Maybe "better multiline..." or "fancy multiline..."? |
Data isn't included in a files that often, I think @StefanKarpinski you might be putting too much aesthetic weight behind indented text. Lua gets this pretty perfect, Python gets it nearly perfect. In Python you can use """\ and it won't insert a leading newline So text_block = """ Will only contain a single newline after the word block with no other formatting applied. It is easy to know what you type is what you will get. If there isn't a another low complexity way of getting verbatim data into the source, maybe an annotation driven approach where the contents of files are injected into vars at runtime/startup. |
I end up having to include data in code quite often, which is what drove the proposed design of this issue. |
How about the native heredoc syntax leaves the string unadulterated and then something like http://docs.python.org/library/textwrap.html can clean up the block if one chooses to indent it? Embedding data into the code is a very important issue for me as well and I would love to see this make it into Julia. |
The textwrap approach is ok; how about a function-encapsulatable text transformer [chain] approach, as Julia has now (focused on numerics)? Also, when this is decided, if something like this is used ... end myInlineData = """ Is there reason not to treat triple-quoted blocks present at the top level of a file and unassigned as a comment? is there any reason that |
+1 for triple quoted strings. They're great when working with HTML, XML, SQL, JSON etc. Given that Julia is REPL-oriented, it is reasonable to expect users to be using data literals quite a bit. |
At least in files, I've noticed that you can do this: function test()
str =
"Hello,
it's a nice
day"
end
julia> test()
"Hello,\nit's a nice\n day" It's not identical to what Stefan proposed (particularly for the first line), but it gets you most of the way there. |
For clarity, I should have also shown:
|
This is a matter of doing some annoying lexer hacking, but one of us should probably bite the bullet and just do it. |
Yeah, the multi-line string is nice -- but the scenario I'm looking at is cutting/pasting text without having to worry about delimiting the quotes, or having to try and read ugly delimited text literals. As a workaround I've been (mis)using command expressions like below, but feeling kind of guilty about it:
[pao: speaking of triple quoting, it works in GitHub Markdown too!] |
possibly relevant: c015463#commitcomment-2505245 |
Update travis to v0.6, drop support for v0.5
New implementation of weighted sum
* Copy across GitHub Action workflows * Add workflow to close stale PRs * Add PR template * Remove codeowners from upstream
Stolen from Python but with some differences:
The point of the
"""
construct is to make it easy to embed snippets of text or code in a readable, nice way inside of Julia code. To that end, it is similar to "here documents" (shell, Perl, Ruby) as well as Python's multiline strings, which use the same delimiters. However, a couple of additional semantics make these more pleasant to use:"""
is on a line followed only by whitespace, that whitespace will be stripped, including the newline."""
token — up to and including the line on which the closing"""
occurs — must begin with the same indentation sequence (identical whitespace characters) as the line on which the opening"""
occurs.After this whitespace stripping is applied, all normal string interpretation is performed as for a
"
string, including unescaping and interpolation. Moreover, you can prefix"""
with an identifier as you can with"
strings to invoke macro-based custom-string forms. Thus, aQ"""
multiline string has no interpolation performed andr"""
is a handy multiline regex literal (maybe thex
extended regex format should always be on).The text was updated successfully, but these errors were encountered: