You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried quoting the following function, making it into a string and back into a quote:
defhi(name)do"hello\n#{name}"end
Currently:
iex(92)>quotedo...(92)> defhi(name)do...(92)>"hello\n#{name}"...(92)>end...(92)>end{:def,[context: Elixir,import: Kernel],[{:hi,[context: Elixir],[{:name,[],Elixir}]},[do: {:<<>>,[],["hello\n",# Note the newline here...{:"::",[],[{{:.,[],[Kernel,:to_string]},[],[{:name,[],Elixir}]},{:binary,[],Elixir}]}]}]]}iex(93)>|>Macro.to_string"def(hi(name)) do\n\"hello\n\#{name}\"\nend"iex(94)>|>tap(&IO.puts/1)def(hi(name))do"hello#{name}"# ...is interpreted as an actual newline instead of being escaped...end"def(hi(name)) do\n\"hello\n\#{name}\"\nend"iex(95)>|>Code.string_to_quoted!{:def,[line: 1],[{:hi,[line: 1],[{:name,[line: 1],nil}]},[do: {:<<>>,[line: 2],["hello\n ",# ...and the indentation after the newline is injected into the string{:"::",[line: 3],[{{:.,[line: 3],[Kernel,:to_string]},[line: 3],[{:name,[line: 3],nil}]},{:binary,[line: 3],nil}]}]}]]}
Expected behavior
I expected iex(95) to be identical to iex(92).
The string interpolation seems necessary to trigger the current behavior.
When I escape the newline as in "hello\\n#{name}", I get the expected behavior, but I can't escape the \n when using a multiline string.
The text was updated successfully, but these errors were encountered:
Environment
Current behavior
I tried quoting the following function, making it into a string and back into a quote:
Currently:
Expected behavior
I expected
iex(95)
to be identical toiex(92)
.The string interpolation seems necessary to trigger the current behavior.
When I escape the newline as in
"hello\\n#{name}"
, I get the expected behavior, but I can't escape the\n
when using a multiline string.The text was updated successfully, but these errors were encountered: