concept shell in category erlang

appears as: shell, The shell, shell, shells
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

Interaction with an Erlang system happens mainly through the shell. The shell is your command central. It’s where you can try out short snippets to see how they work; it’s where you do incremental development and interactive debugging; and it can also be used to control a running system in production. To make you comfortable with working in the shell, the examples are written so that you can try them as you read them. Let’s start a shell right away!

But code that you enter in the shell consists basically of one-off expressions, to be forgotten fairly soon. This code is never part of any module. Therefore, it isn’t possible to use declarations (like -export([...]). or -module(...).) in the shell; there is no module context for such declarations to apply to.

The shell parses expressions and evaluates them by interpreting them on the fly. This is much less efficient (by several orders of magnitude) than running compiled code, but that doesn’t matter much when all it has to do is to perform a call to a function in some existing compiled module (which will run at normal speed)—for example, when you say lists:reverse([1,2,3]). In this case, all the shell does is to prepare the list [1,2,3] and then pass it over to the reverse function (and print the result afterward). Even if it does this at a comparatively slow speed, it’s still much too fast for a human to notice.

It’s possible, though, by use of things such as list comprehensions (explained in section 2.9) or clever use of recursive funs (a neat trick, but may cause the brains of novices to implode), to write code in the shell that is more or less entirely evaluated by the shell’s interpreter from start to end, and that does some significant amount of work. In that case, it will be notably slower than if you had written it in a module and compiled it. So, remember this: never measure on code that is interpreted by the shell. If you want sane numbers from your benchmarks, you must write them as modules, not as shell one-liners. Don’t draw conclusions about efficiency from what the shell does.