How to make IEx print strings instead of charlists

Hi , Trying to understand why"Home", to: '/')
is returning
{:safe, [60, "a", [[32, "href", 61, 34, "/", 34]], 62, "Home", 60, 47, "a", 62]}
instead of
{:safe, ["<a href=\"/\">", "Home", "</a>"]}
like I would expect.

I’m gathering that it’s showing the char codes, but also the nested arrays are throwing me off too.

Thanks for the help!


Hello and welcome,

It is because Phoenix templates use IO list for optimization…

See this post for more information.

1 Like

Thanks for the helpful link. To test my theory I ran

List.to_string elem("Home", to: '/'),1)

and got what I was loooking for.

You can use just to_string btw.

1 Like

Note that single quotes are for charlists. So the '/' you are passing in is not a string but a charlist. It’s a bit odd that it works at all, but when interfacing with Elixir libraries you should use double quoted string literals.