String literal without interpolation

340 views
Skip to first unread message

Jonathan Malmaud

unread,
Dec 3, 2013, 12:43:17 PM12/3/13
to julia...@googlegroups.com
Is there a string prefix that results in no $ interpolation? Like 
@assert raw"$x"[1] == "$"

Stefan Karpinski

unread,
Dec 3, 2013, 12:49:53 PM12/3/13
to Julia Users
There used to be, but it was deleted. I think that many people want it back.

Stefan Karpinski

unread,
Dec 3, 2013, 12:52:42 PM12/3/13
to Julia Users
There's still a vestigial definition of an L_str macro in base/base.jl, but it isn't exported or used anywhere. But I don't really think the L"..." form had ideal behavior anyway. It really ought to at least unescape backslashes.

Jonathan Malmaud

unread,
Dec 3, 2013, 5:01:35 PM12/3/13
to julia...@googlegroups.com
Thanks, I'll open a feature request.

Steven G. Johnson

unread,
Dec 3, 2013, 5:24:04 PM12/3/13
to julia...@googlegroups.com
String macros in general treat everything literally, as Stefan alluded to. I use this in PyPlot to define an L"..." macro for LaTeX. In that context, is is important not to escape backslashes either, so that you can do e.g. L"blah $\sqrt{\alpha}$"

Stefan Karpinski

unread,
Dec 3, 2013, 10:03:43 PM12/3/13
to Julia Users
Right, what I actually meant was removing backslashes when they occur in the input before your quote string (double quote, typically). But I actually think we're already doing this:

julia> macro L_str(s)
         s
       end

julia> L"\""
"\""

julia> L"foo\"\x"
"foo\"\\x"

julia> print(L"foo\"\x")
foo"\x

The backslash before the " disappears while the backslash before the x does not. However, that means that you can't, e.g. pass to a string macro a string ending with a single backslash:

julia> print(L"foo\\")
foo\\

Scott Jones

unread,
Jun 4, 2015, 11:41:40 PM6/4/15
to julia...@googlegroups.com
I would say that is a bug... that `\\` doesn't become `\`.

Stefan Karpinski

unread,
Jun 5, 2015, 10:28:03 AM6/5/15
to Julia Users
This syntax doesn't exist anymore – bug fixed.
Reply all
Reply to author
Forward
0 new messages