Get Started with the Erlang Programming Language: How to Evaluate Simple Statements in an Ericsson Erlang Shell

in utopian-io •  7 years ago 

The Ericsson Erlang programming language was developed for their mobile telephony switches and is now open source. It can handle thousands of parallel, distributed events

Most people will know that Ericsson (in partnership with Sony) are famous for producing a wide range of mobile (or cell) phones, and there are many people who will also know that much of the equipment used to build the mobile telephone networks (built by companies such as Vodafone) is also supplied by Ericsson. However, what most people don't know is that Ericsson have created their own programming language known as Erlang, and not only that: they've even made it open source and freely available for anyone to use.

Ericsson created Erlang for use with their telecommunication equipment (such as their mobile telephony switches) because they needed a language that is:

  • able to handle thousands of events simultaneously
  • able to handle distribution over many computers in different locations
  • able to handle parallel operations
  • above all, to be robust

They were unable to find any language that could do all of that to their satisfaction, and so Erlang was created in the Ericsson Computer Science Laboratory.

Obtaining and Installing Erlang

The Erlang programming language installation application can be downloaded from http://www.erlang.org. Once that's been done then the Erlang emulator can be accessed from the start menu or, if the path is set correctly, then the user just needs to type "erl" on the command prompt. They can then start entering Erlang Code.

Using the Erlang Shell

The Erlang shell (shown in figure 1 at the bottom of this article) is just like any Linux shell or the Windows command prompt:

  • the user types in statements on the command line
  • the interpreter evaluates the statements and displays a result on the screen

So, for example, the user can type in a string such as:

"Hello World".

And the text will be displayed on the screen, or the user could type in:

PI = 3.14159265358979.
R = 5.
C = 2 * PI * R.

This will display 31.4159265358979 on the screen, and there a few things that should be noted from this:

  • every line must be terminated with a full stop (or period)
  • each line is evaluated immediately and the result displayed

previous lines can be accessed by using the drop down list box at the top left of the Erlang console
The next stage is to format the output.

Displaying Outputs in an Erlang Shell

Erlang will immediately evaluate any inputs and display the results of that evaluation. However, in a complex calculation these outputs may be all very confusing. Therefore, the programmer can produce a formatted output by using the io:format method, for example:

io:format ("The circumference of a circle of radius ~w is ~w~n", [R, C]).

The io:format takes two inputs:

a formatted string where:
~w is a place holder for a variable
~n is a new line
the variables to be used in the place holders contained in the formatted string

The output will be something like:

The circumference of a circle of radius 5 is 31.4159265358979

And so, in this way, the programmer can use the Erlang programming language to quickly analyse information and to display it in a useful format. However, all of the code looked at so far can only be used whilst the current Erlang shell is running. It is all lost as soon as the shell is closed.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @alv I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x