Title here
Summary here
Erlang has various value types including strings, integers, floats, atoms (similar to booleans), etc. Here are a few basic examples.
-module(values).
-export([main/0]).
main() ->
% Strings, which can be concatenated with ++
io:format("~s~n", ["erlang" ++ "lang"]),
% Integers and floats
io:format("1+1 = ~p~n", [1 + 1]),
io:format("7.0/3.0 = ~p~n", [7.0 / 3.0]),
% Atoms (similar to booleans), with logical operators
io:format("~p~n", [true and false]),
io:format("~p~n", [true or false]),
io:format("~p~n", [not true]).
To run this Erlang program:
$ erlc values.erl
$ erl -noshell -s values main -s init stop
erlanglang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
In this Erlang code:
values
and export the main/0
function.++
for concatenation.io:format/2
. The first argument is a format string, and ~s
is for strings, ~p
for any term, and ~n
for newline.and
, or
, and not
for boolean operations instead of symbols.true
and false
.Erlang’s syntax and conventions are quite different from many other languages, reflecting its functional and concurrent nature. This example demonstrates some of the basic value types and operations in Erlang.