@@ -552,7 +552,8 @@ defmodule Code do
552
552
all imports, requires and aliases defined in the current environment
553
553
will be automatically carried over:
554
554
555
- iex> {result, binding} = Code.eval_string("a + b", [a: 1, b: 2], __ENV__)
555
+ iex> require Integer
556
+ iex> {result, binding} = Code.eval_string("if Integer.is_odd(a), do: a + b", [a: 1, b: 2], __ENV__)
556
557
iex> result
557
558
3
558
559
iex> Enum.sort(binding)
@@ -975,12 +976,18 @@ defmodule Code do
975
976
the code representation (AST). While the formatter can preserve code
976
977
comments between expressions and function arguments, the formatter
977
978
cannot currently preserve them around operators. For example, the following
978
- code will move the code comments to before the operator usage :
979
+ code:
979
980
980
981
foo() ||
981
982
# also check for bar
982
983
bar()
983
984
985
+ will move the code comments to before the operator usage:
986
+
987
+ # also check for bar
988
+ foo() ||
989
+ bar()
990
+
984
991
In some situations, code comments can be seen as ambiguous by the formatter.
985
992
For example, the comment in the anonymous function below
986
993
@@ -1247,6 +1254,14 @@ defmodule Code do
1247
1254
* atoms used to represent single-letter sigils like `:sigil_X`
1248
1255
(but multi-letter sigils like `:sigil_XYZ` are encoded).
1249
1256
1257
+ ## Examples
1258
+
1259
+ iex> Code.string_to_quoted("1 + 3")
1260
+ {:ok, {:+, [line: 1], [1, 3]}}
1261
+
1262
+ iex> Code.string_to_quoted("1 \ 3")
1263
+ {:error, {[line: 1, column: 4], "syntax error before: ", "\" 3\" "}}
1264
+
1250
1265
"""
1251
1266
@ spec string_to_quoted ( List.Chars . t ( ) , keyword ) ::
1252
1267
{ :ok , Macro . t ( ) } | { :error , { location :: keyword , binary | { binary , binary } , binary } }
@@ -2085,7 +2100,7 @@ defmodule Code do
2085
2100
2086
2101
## Examples
2087
2102
2088
- iex> Code.loaded?(Atom )
2103
+ iex> Code.loaded?(String )
2089
2104
true
2090
2105
2091
2106
iex> Code.loaded?(NotYetLoaded)
0 commit comments