二郎/OTP : Changes to the already existing modules

标签 erlang erlang-otp

我正在研究一个问题的解决方案,该问题需要更改模块 gb_trees 的其中一个功能。

我在编译 gb_trees 的编辑版本时遇到错误:

1> c(gb_trees).
cannot write to .bea#
...
2>

我可以通过什么方式来修改和编译一个已经存在的模块?

最佳答案

可能您的文件正在被另一个进程使用。关闭您正在使用的所有应用程序或重新启动操作系统,然后尝试重新编译。

您正在尝试手动加载模块,它是 Erlang/OTP 的一部分。

来自文档:

The Erlang runtime system is protecting you.

The easiest solution is to rename your module, e.g. to mysets.erl. It is also possible to 'un-stick' the directory containing the library module.

参见 code:unstick/1 .

还有:

To prevent accidentally reloading modules affecting the Erlang runtime system itself, the kernel, stdlib and compiler directories are considered sticky. This means that the system issues a warning and rejects the request if a user tries to reload a module residing in any of them. The feature can be disabled by using the command line flag -nostick.

参见 erl(1) .

例如:

$ erl -nostick
Eshell V5.7.3  (abort with ^G)
1> c(gb_trees).
{ok,gb_trees}
2> gb_trees:module_info().
[{exports,[{foo,2},{module_info,0},{module_info,1}]},
 {imports,[]},
 {attributes,[{vsn,[338095567601101424197378397768992511838]}]},
 {compile,[{options,[]},
           {version,"4.6.3"},
           {time,{2011,2,3,11,39,53}},
           {source,"/tmp/gb_trees.erl"}]}]
3>

您会看到我们可以编译模块并将其加载到 VM 中。

但是,您可以将模块 gb_trees 重命名为 gb_trees_mine 并使用它导出的函数:

1> gb_trees_mine:foo(13,42).
bar
2>

关于二郎/OTP : Changes to the already existing modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4885443/

相关文章:

list - 如何在不在erlang中创建新变量的情况下将元素添加到现有列表?

erlang - 如何让 Rebar 在发布目录中运行 Common Test?

erlang - 如何从受监督的工作进程中触发 Elixir 主管树终止

Erlang/OTP 框架的 error_logger 在相当高的负载下挂起

erlang - Erlang的外部术语格式定义稳定吗?如果没有,用什么?

erlang - CouchDB文档更新处理程序可以获取更新冲突吗?

erlang - 从网络分区进行在线内存恢复

Erlang 全局和本地名称

elixir - 为什么 Supervisor.start_child 不起作用

ubuntu - 如何在 Ubuntu 18/19 上升级 Elixir 版本