user12474324
user12474324

Reputation: 55

Can you use the introspection function outside of iex?

Can I use i() from outside of iex? Are there other functions you can only access inside iex?

iex> i(3)
Term
  3
Data type
  Integer
Reference modules
  Integer
Implemented protocols
  IEx.Info, Inspect, List.Chars, String.Chars

bash> elixir -e "i(3)"
** (CompileError) nofile:1: undefined function i/1
(elixir 1.11.1) lib/code.ex:341: Code.eval_string_with_error_handling/3

Upvotes: 2

Views: 77

Answers (1)

Brett Beatty
Brett Beatty

Reputation: 5963

i/1 is an import of IEx.Helpers.i/1, so when it's available you can use the fully qualified name:

$ elixir -e 'IEx.Helpers.i(3)'
Term
  3
Data type
  Integer
Reference modules
  Integer
Implemented protocols
  IEx.Info, Inspect, List.Chars, String.Chars

If for some reason you want to use it within your own application, make sure to add :iex to :extra_applications in your mix.exs. Otherwise you'll get a warning about your application not depending directly on the :iex application (might just be newer versions of Elixir).

To answer your second question, I would imagine all of the helpers in IEx.Helpers were intended to be be used only within IEx. You can see these in IEx by calling h(), which is imported from IEx.Helpers.h/0, which prints the docs for IEx.Helpers.

Upvotes: 5

Related Questions