gpt4 book ai didi

erlang - 当编译的代码与 shell 评估的不同时?

转载 作者:行者123 更新时间:2023-12-04 05:43:26 24 4
gpt4 key购买 nike

Erlang and OTP in Action (第 46 页),作者在注释中陈述了以下内容:

It may happen that in some odd corner case, code evaluated in the shell behaves slightly differently from the same code when compiled as part of a module. In such a case, the compiled version is the gold standard. The shell tries its best to do the exact same thing when it interprets the expressions.



你能想到一个或多个这些奇怪的极端情况吗?在这些情况下,有哪些细微差别?

最佳答案

erlang 解释器,erl_eval , 非常努力地表现得与编译代码完全一样。如果不是,则很可能是错误。

除了 在一种情况下,那就是接收消息。编译后的代码可以访问内部指令来访问和操作消息队列。口译员不能这样做。它必须:实际上从队列中删除消息(或多或少与 receive X -> X end );测试它们以查看它们是否与接收模式匹配;保留那些不匹配的;并将所有当前不需要的消息放回队列中(通过接收 所有 消息,然后将它们发送回自身)。这意味着在很短的时间内,如果消息到达,它可能不会像编译代码那样在消息队列中的相同位置结束。

关于erlang - 当编译的代码与 shell 评估的不同时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4548041/

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