Lisp 风格的 Erlang - 消息传递原语
我已经阅读了所有文档以及 LFE 的大部分源代码。所有演示都强调传统 lisp 角色中的基本 lisp - 一般问题解决、Hello world 和语法模拟宏。
有谁知道 LFE 如何处理消息原语?为了指定一个更精确的问题,你会如何表达这个 erlang:
A = 2,
Pid = spawn(fun()->
receive
B when is_integer(B) -> io:format("Added: ~p~n",[A+B]);
_ -> nan
end
end),
Pid ! 5.
然后,你知道,它咕哝着一些数字相加,答案是 7。
I've read through all the documentation, and most of the source of LFE. All the presentations emphasize basic lisp in traditional lisp roles - General Problem Solving, Hello world and syntax emulating macros.
Does anyone know how LFE handles messaging primitives? To specify a more precise question, how would you express this erlang:
A = 2,
Pid = spawn(fun()->
receive
B when is_integer(B) -> io:format("Added: ~p~n",[A+B]);
_ -> nan
end
end),
Pid ! 5.
And then, you know, it mumbles something about having added up some numbers and the answer being 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 LFE 用户,但有一个用户指南 在源代码树中。通过阅读它,我猜它是这样的:
但我很可能犯了一个错误,因为我什至没有在 LFE 中评估过它。
我的一些问题:
LET*
形式或者它的行为已经像这样了?I'm not an LFE user, but there is a user guide in the source tree. From reading it I would guess it is something like this:
But I'm very likely to have made a mistake since I haven't even evaluated it in LFE.
Some questions of mine:
LET*
form or is it behaving like one already?LFE 版本中严重缺乏示例,欢迎所有贡献。
克里斯蒂安的建议是正确的。我唯一的评论是变量名不需要大写,这没有错,但没有必要。
LFE
let
是一个“真正的”let,其中变量绑定首先在主体中可见。您可以在 let 中使用模式。还有一个按顺序绑定的let*
形式(实际上是宏)。不,到目前为止,我保留了所有 Erlang 核心函数名称,就像它们在 vanilla erlang 中一样。在名称中使用
-
而不是_
肯定更加口齿不清,但是如何处理 OTP 中的所有其他函数名称和原子呢?一个建议是自动将 LFE 符号中的-
映射到生成的原子中的_
,当然,然后再以另一种方式返回。这可能会起作用,但是会导致混乱吗?然后我可以有一个如下所示的行为模块:
但我对此非常矛盾。
There is a serious lack of examples in the LFE release, all contributions are welcome.
Christian's suggestion is correct. My only comment is that there is no need to have capitalized variable names, it is not wrong, but not necessary.
The LFE
let
is a "real" let in which the variable bindings are visible first in the body. You can use patterns in let. There is also alet*
form (macro actually) which binds sequentially.No, I have so far kept all the Erlang core function names just as they are in vanilla erlang. It is definitely more lispy to use
-
instead of_
in names, but what do you do with all the other function names and atoms in OTP? One suggestion is to automatically map-
in LFE symbols to_
in the resultant atoms, and back again going the other way of course. This would probably work, but would it lead to confusion?I could then have a behaviour module looking like:
But I am very ambivalent about it.