String representation of expression

I once developed a macro which would take the enclosed code block and write it to a file which would then later be included in another julia process. In principle I just printed the expression into the file which would then happly run once included - in julia v1.3:

julia-1.3> print(:(r = r"""45 " """))
r = #= REPL[1]:1 =# @r_str("45 \" ")

However with julia v1.4 this does not work anymore, since quotes in triple-quoted strings and escaped quotes in quoted strings are not faithfully represented anymore if they appear in a non-standard string literal:

julia-1.4> print(:(r = r"""45 " """))
r = r"45 " "
julia-1.4> print(:(r = r"45 \" "))
r = r"45 " "

in normal string everything seems fine:

Julia-1.4> print(:(r = "45 \" "))
r = "45 \" "

Is there another way I should use to print an expression such that it can be included again?

Thanks

Probably not a great answer (and probably overkill) but:

julia>  print(:(r = $(esc(r"""45 " """).args[1])))
r = r"45 \" "

on nightly

This looks like a printing bug. Could you open an issue on GitHub?

Done: https://github.com/JuliaLang/julia/issues/35305#issue-590299078

1 Like