Skip to content
Jason Charney edited this page Apr 18, 2016 · 3 revisions

🚧 NEW PAGE! I though I just make this page for anyone whose interested.

Erlang is a programming language used to build massively scalable soft reap-time systems with requirements of high availablity . Some of its uses are in telecoms, banking, e-commerce, computer telephony, and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution, and fault tolerance.

TLDR: It's a scalable programming language.

Erlang's bread and butter is OTP, a set of erlang libraries and design principles providing middle-ware to develop systems. It isncludes it's own distributed database, applications to interface towards other languages, and debugging and release handling tools.

Why is this of any concern?

When I was installing [Apache Thrift](Apache Thrift) for GNU Radio, one of the add on options was for Erlang. We'll want to install OTP and Rebar3, Erlang's build too.

Prerequirments

What you'll defintely need

  • GNU make
  • A C compler like GCC or [Clang](LLVM and Clang)
  • Perl 5 (which you should have on your system if you ae using Linux or UNIX.)
  • GNU m4
  • ncurses, termcap, or termlib. To make this easy, follow the instructions for Tmux installation.
  • sed, the stream editor. If you don't have it, apt-get it. Ditto for gawk because for some reason a lot of other AWKs that aren't gawk have been installed lately.
  • GNU autoconf

I also recomend these "optional" components.

  • OpenSSL (libssl-dev or something.)
  • Oracle's version of Java. (I've got instructions for that.)
  • flex, which means you should also download bison.
  • X Windows -- The development headers and libraries are needed to build the Erlang/OTP application gs. Hopefully that doesn't clash with GhostScript
  • wxWidgets

Installation

TODO: I need to add instructions for installing the documentation!

$ cd ~/Software
$ mkdir erlang
$ cd erlang
$ git clone https://github.com/erlang/otp/
$ git clone https://github.com/erlang/rebar3/
$ cd otp
$ ./otp_build autoconf     # generate the configure file.
$ ./configure
$ ./make -j4
$ sudo make install
$ cd ..
$ cd rebar3
$ ./boostrap
$ ./rebar3 local install
$ echo "export PATH=\$PATH:\$HOME/.cache/rebar3/bin" >> ~/.bashrc	# Add rebar3 to your PATH!

Erlang and Rebar3 should now be installed.

Erlang should be located at /usr/local/bin/erl. If you ask where erlang is with whereis it will point to /usr/local/lib/erlang which is not the application, and which will reply nothing. However, if you use whereis or which with erl, it will point to /usr/local/bin/erl

I wish the Erlang folks would have considered putting Rebar3 in /usr/local and that they would have added a link to erl called erlang.

I didn't install documentation for Erlang because of how this installation instructions were written and how the installation was structured.

Hello World

Much like Scala, Erlang has several way you can write your code.

In the shell

Notice that lines in Erlang end with a period.

$ erl -noshell -eval 'io:fwrite("Hello, world!\n"), init:stop().'
Hello, World!

As a shell script

Use a text editor to make hello.sh

#! /usr/bin/env escript
% HelloWorld.erl.sh
main(_) -> io:fwrite("Hello, world!\n").

Run it like this

$ chmod u+x hello.erl.sh
$ ./hello.erl.sh
Hello, World!

Compile it and Execute it

Of course, most people would prefer to work with erlang like they would with Scala or Java: Compilation and Execution

% hello.erl
-module(hello).
-export([start/0]).

start() ->
	io:fwrite("Hello, world!\n").

Compile and execute. erlc hello.erl creates hello.beam.

$ erlc hello.erl
$ erl -noshell -s hello start -s init stop
Hello, world!

That is completely nasty. It works, but I think that erl step could have been nicer. I'll have to look up a better version of this later.

TODO: Find a better erl compile command or a better hello.erl file.

REPL

Erlang does have a REPL. To leave it press Ctrl+</kbd> (backslash) or use init:stop().

It turns out in this example, yo need to write hello.erl first, which is why this section followed the previous section.

$ erl
Erlang/OTP 18 [erts-7.3] [source-523e048] [smp:4:4] aync-threads:10] [hipe] [kernel-poll:false]

Eshell V7.3 (abort with ^G)
1> c(hello).
{ok,hello}
2> hello:start().
Hello, world!
ok
3>			% Ctrl+\

Other things to note

  • Erlang's EDoc documentation generator is inspired by Javadoc, but uses the same style of comments used in PostScript

See Also

Links

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux
Clone this wiki locally