开发者

Is there a full REPL for Erlang?

Is there a way to have a full interpreter in Erlang, not just a "shell".

Since it is a dynamic language, not being able to define named functions in the interpreter is a little bit disa开发者_开发问答ppointing... I suspect that it is because compilation units (modules) must be explicitly compiled for their execution by the VM, but maybe a REPL acting as a dynamic/recompilable module exist?


> F= fun () -> io:format("Hello World~n", []) end.
> F().


The short answer is NO, it does fit into the way that Erlang handles code.

The Erlang VM only supports compiled code. The unit of code handling, including compilation, is the module, you load, delete, update and purge modules. So it is not really possible to mix interpreted and compiled functions the same way as you can in lisp. It would be possible to extend the shell to allow defining interpreted functions within it but these would then only be callable from within shell interpreter and not from other modules. It would also be possible to make the shell recompile and reload "shell module" so functions within it could be called from other modules. But this module would then only really exist within that invocation of erlang.

And I honestly don't really see the point as recompiling and reloading code has always been so fast it has not been a problem. It would more be force of habit than convenience.


This is related to Defining erlang functions in the shell

Short answer:

  • Use funs

Longer answer:

  • http://ulf.wiger.net/weblog/2007/11/20/extending-the-erlang-shell-part-1/
  • http://ulf.wiger.net/weblog/2007/11/21/extending-the-erlang-shell-part-2/
  • http://erldocs.com/R13B04/stdlib/shell_default.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜