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 raw_str macro for strings with no interpolation/unescaping #19900

Merged
merged 1 commit into from
Jan 8, 2017

Conversation

kleinhenz
Copy link
Contributor

This implements a raw_str macro that allows input of strings with no interpolation/unescaping as discussed in issue #11567 and #11764. I understand this functionality (as L_str) was removed by commit 7123ad3 following discussion in issue #107. However, I think this merits reconsideration for a couple reasons.

  1. This feature is useful as a base for working with strings that represent code/markup in other languages. This is reimplemented in packages that deal with these situations, e.g. LaTeXStrings, but the core functionality seems sufficiently general to merit inclusion in base.

  2. Although the implementation of raw_str is basically trivial, it has very low discoverability to new users, especially people coming from python who expect to have the functionality builtin. Users wanting to use raw strings shouldn't have to go through stack overflow to implement this functionality themselves.

  3. raw_str is clear, concise and provides a useful base for more complicated use cases. Because raw_str doesn't unescape anything, it is possible to define exactly what you want to unescape in julia, e.g. unescape(raw"...") will unescape traditional c/unicode escape sequences but leave $ escaped and avoid interpolation. This seems much cleaner than some proposals for using string macro suffixes to specify exactly what to unescape. Also to me raw"..." seems more self-documenting than L"..." or '''...''' and adds the minimal amount of additional complexity to the strings ecosystem.

Apologies in advanced if this has already been hashed out beyond the discussions I was able to find, but given the two open issues I thought it was worth submitting a PR to see if we can figure out something that can be merged into master.

This duplicates PR #19254 which I closed/deleted because there was no response so I assumed there wasn't interest. However, since closing that PR it seems that there is at least some interest so I am creating this new PR. Unfortunately I can't reopen the old one because the branch is deleted. Apologies for the clutter.

Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski left a comment

Choose a reason for hiding this comment

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

Looks good. Of course we've got to bikeshed the prefix, but raw"..." seems pretty reasonable to me.

@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Jan 6, 2017
@kshyatt kshyatt added the domain:strings "Strings!" label Jan 6, 2017
Raw strings without interpolation or unescaping can be expressed with
non-standard string literals of the form `raw"..."`. Raw string literals
create ordinary `String` objects which contain the enclosed contents exactly
as entered with no interpolation or unescaping. This is useful for strings which
Copy link
Member

Choose a reason for hiding this comment

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

The exception is quotation marks, which are still escaped, e.g. raw"\"" is equivalent to "\""

Copy link
Contributor

Choose a reason for hiding this comment

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

that's worth noting

Copy link
Contributor

Choose a reason for hiding this comment

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

won't get addressed if it remains a comment on a closed pr. open an issue or pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated documentation to note exception in #20239

@ararslan
Copy link
Member

ararslan commented Jan 6, 2017

Thanks for revisiting this! As Kristoffer mentioned in the previous version of this PR, this is very well thought out. It's an exceptional first contribution to Julia. Nice work!

@StefanKarpinski StefanKarpinski merged commit f02fcc6 into JuliaLang:master Jan 8, 2017
@cormullion
Copy link
Contributor

Should this go into News.md? Looks quite useful.

@tkelman tkelman added the needs news A NEWS entry is required for this change label Jan 17, 2017
@kleinhenz kleinhenz deleted the raw_string branch January 23, 2017 19:28
@kleinhenz kleinhenz restored the raw_string branch January 26, 2017 01:49
@kleinhenz kleinhenz deleted the raw_string branch January 26, 2017 01:55
@Sacha0 Sacha0 removed the needs news A NEWS entry is required for this change label May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants