Let's try creating a simple program using basic development tools.
- Prerequisite: Erlang development environment setup
Creating the First Program in Erlang
$ rebar3 help new
Create rebar3 project based on template and vars.
Valid command line options:
<template> [var=foo,...]
See available templates with: `rebar3 new help`
Usage: rebar3 new [-f]
-f, --force overwrite existing files
$ rebar3 new help
Call `rebar3 new help <template>` for a detailed description
app (built-in): Complete OTP Application structure.
cmake (built-in): Standalone Makefile for building C/C++ in c_src
escript (built-in): Complete escriptized application structure
lib (built-in): Complete OTP Library application (no processes) structure
plugin (built-in): Rebar3 plugin project structure
release (built-in): OTP Release structure for executable programs
umbrella (built-in): OTP structure for executable programs (alias of 'release' template)
$ rebar3 new app first_program
===> Writing first_program/src/first_program_app.erl
===> Writing first_program/src/first_program_sup.erl
===> Writing first_program/src/first_program.app.src
===> Writing first_program/rebar.config
===> Writing first_program/.gitignore
===> Writing first_program/LICENSE
===> Writing first_program/README.md
src/first_program_app.erl
%%%-------------------------------------------------------------------
%% @doc first_program public API
%% @end
%%%-------------------------------------------------------------------
-module(first_program_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
first_program_sup:start_link().
stop(_State) ->
ok.
%% internal functions
src/first_program_sup.erl
%%%-------------------------------------------------------------------
%% @doc first_program top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(first_program_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%% sup_flags() = #{strategy => strategy(), % optional
%% intensity => non_neg_integer(), % optional
%% period => pos_integer()} % optional
%% child_spec() = #{id => child_id(), % mandatory
%% start => mfargs(), % mandatory
%% restart => restart(), % optional
%% shutdown => shutdown(), % optional
%% type => worker(), % optional
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_all,
intensity => 0,
period => 1},
ChildSpecs = [],
{ok, {SupFlags, ChildSpecs}}.
%% internal functions
Build:
$ rebar3 compile
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling first_program
C C++ C# Clojure Crystal D Dart F# Go Haskell Java Javascript Julia Kotlin Lua Python Rust Scala Swift Typescript