New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add String.to_atom(:atom) #2915
Comments
@mgwidmann I'm not sure I understand, why would you call |
@bitwalker Like this (only assume the data is coming from somewhere else, not hard coded): defmodule MyModule do
["one_#{:something_interpolated}", :two, "three_#{:something_else}", :four] |> Enum.each fn(v)->
def unquote(String.to_atom(v))(), do: :the_return_value
end
end My point is that |
I guess maybe what I'm suggesting instead is that |
Some application can tackle to_atom or define the Atom.Chars protocol. The trouble though is that we want developers to be much more careful about converting stuff to atom as they are not garbage collected so I don't think we should ship it directly in Elixir. Thank you! |
Ok, that sounds reasonable. Question though, in the above code snippet without the |
It is definitely not valid syntax! On Thursday, December 4, 2014, Matt notifications@github.com wrote:
José Valimwww.plataformatec.com.br |
Currently
to_string
supports both atoms and binaries, however converting to atoms does not.This makes it tedious to have to run values through code like
value |> to_string |> String.to_atom
when all that is really desired is forString.to_atom(value)
to work regardless ifvalue
is a binary or an atom.I attempted to make this modification, but it seems its far more complicated than just adding
above the
String.to_atom/1
definition. I found theelixir_rewrite.erl
module and attempted to modify it but couldn't find what the correct solution would be to make the tests pass (otherwise this would be a pull request 😭)The text was updated successfully, but these errors were encountered: