Bug when in string interpolation?

70 views
Skip to first unread message

eksperimental

unread,
May 31, 2016, 7:53:33 PM5/31/16
to elixir-l...@googlegroups.com
I came across when writing a macro that created functions after atoms.
I had the idead that to convert from atom to string, we could
interpolate the atom into the string, or we could use Atom.to_string/1.

Interactive Elixir (1.2.4) - press Ctrl+C to exit (type h() ENTER for
help) iex(1)> atom = :foo :foo iex(2)> atom |> Atom.to_string
"foo"
iex(3)> "#{atom}"
"foo"
iex(4)> atom = :nil
nil
iex(5)> atom |> Atom.to_string
"nil"
iex(6)> "#{atom}"
""


Is this a bug?

José Valim

unread,
Jun 1, 2016, 3:07:52 AM6/1/16
to elixir-l...@googlegroups.com
No because interpolation uses the Strint.Chars protocol that defines a different behavior for nil while Atom.to_string keeps a literal conversion.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20160601065326.4fd4c576.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.


--


José Valim
Skype: jv.ptec
Founder and Director of R&D

eksperimental

unread,
Jun 1, 2016, 5:21:39 PM6/1/16
to elixir-l...@googlegroups.com
great,
just wanted to make sure this was the intented behaviour.
Good to know and remember the are not the same.
> > <javascript:;>. To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages