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

RFC: add triple-quote string literals, e.g., """abc""" #2305

Merged
merged 4 commits into from
Feb 19, 2013

Conversation

nolta
Copy link
Member

@nolta nolta commented Feb 15, 2013

No description provided.

@catawbasam
Copy link
Contributor

woot!

For example,

    s = """
        a
         b
        """

is now equivalent to "a\n b".
@nolta
Copy link
Member Author

nolta commented Feb 16, 2013

Now w/ whitespace prefix stripping:

julia> s = """
           a
            b
           """
"a\n b"

@kmsquire
Copy link
Member

In this incarnation, it seems impossible to intentionally indent text and simultaneously leave off a trailing newline.

@nolta
Copy link
Member Author

nolta commented Feb 17, 2013

@kmsquire Which incarnation?

julia> s = """
            a
            b
           """
" a\n b"

julia> s = """
            a
            b\n
           """
" a\n b\n"

@JeffBezanson
Copy link
Sponsor Member

True, if you want a trailing newline it's easy to just add one:

julia> str = """
               Hello,
               world.
             """
"  Hello,\n  world."

julia> str = """
               Hello,
               world.

             """
"  Hello,\n  world.\n"

@kmsquire
Copy link
Member

Sorry @nolta, I had misinterpreted your statement about stripping newlines--I agree that they should be stripped at the end. WITHOUT stripping, as @StefanKarpinski wants, would make it hard to intentionally indent and leave off a final newline.

(Note to self to actually test code before commenting... :-/)

@JeffBezanson
Copy link
Sponsor Member

Ok, let's merge this! It doesn't break anything and we can tweak if necessary. I think we should go with nolta's behavior since it's easier to add more newlines than to figure out how to get rid of a newline you don't want.

@StefanKarpinski
Copy link
Sponsor Member

I object:

  • Bash, Perl and Ruby all keep the trailing newline in their here docs.
  • Python and Ruby's triple quotes keep the trailing newline (of course, they also keep the leading newline).
  • I cannot recall a single time in all of these languages that I've ever needed to strip the trailing newline off of a multiline here doc / triple quote. Sure, I want to get rid of the leading newline, that's an annoyance, but you want the trailing newline.

@StefanKarpinski
Copy link
Sponsor Member

I should clarify that I only object to not keeping the trailing newline. The rest of it is great.

@JeffBezanson
Copy link
Sponsor Member

Ok, I won't hold up merging over this. Not that important to me.

Restores the trailing newline when the terminator occupies its own line.
Otherwise, instead of using the last line to set the deindent level,
scan for the longest common prefix.

Also, handle tab/space mixing.
@nolta
Copy link
Member Author

nolta commented Feb 19, 2013

Ok, i pushed a fix which hopefully makes everybody happy:

s = """
     a
    """  # == " a\n"

s = """
     a"""  # == "a"

@StefanKarpinski
Copy link
Sponsor Member

Excellent.

StefanKarpinski added a commit that referenced this pull request Feb 19, 2013
add triple-quote string literals, e.g., """abc"""
@StefanKarpinski StefanKarpinski merged commit a30fe7d into master Feb 19, 2013
@nolta nolta deleted the mn/triplequote branch February 19, 2013 21:15
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.

None yet

5 participants