gpt4 book ai didi

bash - 可以在 iex 之外使用内省(introspection)功能吗?

转载 作者:行者123 更新时间:2023-12-02 19:02:52 25 4
gpt4 key购买 nike

我可以从 iex 外部使用 i() 吗?还有其他只能在 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

最佳答案

i/1IEx.Helpers.i/1 的导入,因此当它可用时,您可以使用完全限定名称:

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

如果由于某种原因您想在自己的应用程序中使用它,请确保添加 :iex:extra_applications在你的mix.exs 。否则,您将收到有关您的应用程序不直接依赖于 :iex 的警告。应用程序(可能只是 Elixir 的较新版本)。

为了回答你的第二个问题,我想象 IEx.Helpers 中的所有助手。旨在仅在 IEx 内使用。您可以通过调用 h() 在 IEx 中查看这些内容,从 IEx.Helpers.h/0 导入,它打印 IEx.Helpers 的文档.

关于bash - 可以在 iex 之外使用内省(introspection)功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65359243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com