'\n' is not working in `print` for customized string literals

For custom string literals, you get the raw string without processing of escape characters or interpolations. It’s up to you to implement those extra behaviors if desired:

julia> macro blah_str(str)
           for c in str
               println(repr(c))
           end
       end
@blah_str (macro with 1 method)

julia> blah"\n$x"
'\\'
'n'
'$'
'x'

Doing something like Meta.parse('"' * replace(str, '"' => "\\\"") * '"') inside the macro and processing the resulting string or AST can be a convenient way to recover the usual interpolation support.

2 Likes