-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Improve docs for Code module
#14456
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
Improve docs for Code module
#14456
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -552,7 +552,8 @@ defmodule Code do | |
| all imports, requires and aliases defined in the current environment | ||
| will be automatically carried over: | ||
|
|
||
| iex> {result, binding} = Code.eval_string("a + b", [a: 1, b: 2], __ENV__) | ||
| iex> require Integer | ||
| iex> {result, binding} = Code.eval_string("if Integer.is_odd(a), do: a + b", [a: 1, b: 2], __ENV__) | ||
| iex> result | ||
| 3 | ||
| iex> Enum.sort(binding) | ||
|
|
@@ -975,12 +976,18 @@ defmodule Code do | |
| the code representation (AST). While the formatter can preserve code | ||
| comments between expressions and function arguments, the formatter | ||
| cannot currently preserve them around operators. For example, the following | ||
| code will move the code comments to before the operator usage: | ||
| code: | ||
|
|
||
| foo() || | ||
| # also check for bar | ||
| bar() | ||
|
|
||
| will move the code comments to before the operator usage: | ||
|
|
||
| # also check for bar | ||
| foo() || | ||
| bar() | ||
|
|
||
| In some situations, code comments can be seen as ambiguous by the formatter. | ||
| For example, the comment in the anonymous function below | ||
|
|
||
|
|
@@ -1247,6 +1254,14 @@ defmodule Code do | |
| * atoms used to represent single-letter sigils like `:sigil_X` | ||
| (but multi-letter sigils like `:sigil_XYZ` are encoded). | ||
|
|
||
| ## Examples | ||
|
|
||
| iex> Code.string_to_quoted("1 + 3") | ||
| {:ok, {:+, [line: 1], [1, 3]}} | ||
|
|
||
| iex> Code.string_to_quoted("1 \ 3") | ||
| {:error, {[line: 1, column: 4], "syntax error before: ", "\"3\""}} | ||
|
|
||
| """ | ||
| @spec string_to_quoted(List.Chars.t(), keyword) :: | ||
| {:ok, Macro.t()} | {:error, {location :: keyword, binary | {binary, binary}, binary}} | ||
|
|
@@ -1600,8 +1615,8 @@ defmodule Code do | |
|
|
||
| ## Examples | ||
|
|
||
| Code.get_compiler_option(:debug_info) | ||
| #=> true | ||
| iex> Code.get_compiler_option(:debug_info) | ||
| true | ||
|
|
||
| """ | ||
| @doc since: "1.10.0" | ||
|
|
@@ -1710,8 +1725,8 @@ defmodule Code do | |
|
|
||
| ## Examples | ||
|
|
||
| Code.put_compiler_option(:debug_info, true) | ||
| #=> :ok | ||
| iex> Code.put_compiler_option(:debug_info, true) | ||
|
||
| :ok | ||
|
|
||
| """ | ||
| @doc since: "1.10.0" | ||
|
|
@@ -2085,11 +2100,11 @@ defmodule Code do | |
|
|
||
| ## Examples | ||
|
|
||
| iex> Code.loaded?(Atom) | ||
| true | ||
| Code.loaded?(Atom) | ||
|
||
| #=> true | ||
|
|
||
| iex> Code.loaded?(NotYetLoaded) | ||
| false | ||
| Code.loaded?(NotYetLoaded) | ||
| #=> false | ||
|
|
||
| """ | ||
| @doc since: "1.15.0" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reading global state and some tests may change this.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I get it, with
mix testit could befalse. And put into it is even worse. Reverted, will be more careful with changes