@@ -57,6 +57,12 @@ defmodule Code do
5757 :code . del_path ( Path . expand to_char_list ( path ) )
5858 end
5959
60+ @ doc false
61+ def eval ( string , binding // [ ] , opts // [ ] ) do
62+ IO . write "[WARNING] Code.eval is deprecated, please use Code.eval_string instead\n #{ Exception . format_stacktrace } "
63+ eval_string ( string , binding , opts )
64+ end
65+
6066 @ doc """
6167 Evalutes the contents given by string. The second argument is the
6268 binding (which should be a keyword) followed by a keyword list of
@@ -84,24 +90,24 @@ defmodule Code do
8490
8591 ## Examples
8692
87- iex> Code.eval ("a + b", [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line)
93+ iex> Code.eval_string ("a + b", [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line)
8894 { 3, [ {:a, 1}, {:b, 2} ] }
8995
9096 For convenience, you can my pass `__ENV__` as argument and
9197 all imports, requires and aliases will be automatically carried
9298 over:
9399
94- iex> Code.eval ("a + b", [a: 1, b: 2], __ENV__)
100+ iex> Code.eval_string ("a + b", [a: 1, b: 2], __ENV__)
95101 { 3, [ {:a, 1}, {:b, 2} ] }
96102
97103 """
98- def eval ( string , binding // [ ] , opts // [ ] )
104+ def eval_string ( string , binding // [ ] , opts // [ ] )
99105
100- def eval ( string , binding , Macro.Env [ ] = env ) do
101- eval ( string , binding , env . to_keywords )
106+ def eval_string ( string , binding , Macro.Env [ ] = env ) do
107+ eval_string ( string , binding , env . to_keywords )
102108 end
103109
104- def eval ( string , binding , opts ) do
110+ def eval_string ( string , binding , opts ) do
105111 { value , binding , _scope } =
106112 :elixir . eval :unicode . characters_to_list ( string ) , binding , opts
107113 { value , binding }
@@ -111,7 +117,7 @@ defmodule Code do
111117 Evalutes the quoted contents.
112118
113119 This function accepts a list of environment options.
114- Check `Code.eval ` for more information.
120+ Check `Code.eval_string ` for more information.
115121
116122 ## Examples
117123
@@ -153,6 +159,11 @@ defmodule Code do
153159 * `:existing_atoms_only` - When true, raises an error
154160 when non-existing atoms are found by the tokenizer.
155161
162+ ## Macro.to_binary/1
163+
164+ The opposite of converting a string to its AST is
165+ `Macro.to_binary`, which converts a AST to a binary
166+ representation.
156167 """
157168 def string_to_ast ( string , opts // [ ] ) do
158169 file = Keyword . get opts , :file , "nofile"
0 commit comments