c("user.exs")
在内存中编译文件并且不将字节码(.beam 文件)写入磁盘,而h/1
当前需要(详情如下)在磁盘上存在梁文件才能工作。您可以c
将生成的字节码存储在当前目录中,这样可以h/1
使用c("user.exs", ".")
:
$ ls
user.exs
$ cat user.exs
defmodule User do
@moduledoc """
Defines the user struct and functions to handle users.
"""
end
$ iex
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.4.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c("user.exs", ".")
[User]
iex(2)> h User
User
Defines the user struct and functions to handle users.
iex(3)>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
^C
$ ls
Elixir.User.beam user.exs
h/1
依赖于Code.get_docs/2
获取调用:code.get_object_code/1
模块的文档。:code.get_object_code/1
根据其文档,“搜索模块模块的目标代码的代码路径。{Module, Binary, Filename}
如果成功则返回,否则error
。”