Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Erlang Online

% hello world program
-module(helloworld).
-export([for/2]).

for(Initial,Final) ->
    
     if
        (Initial == Final) ->
            Initial;
    true ->
        
           Initial,
           for(Initial+1,Final)
    end.

Erlang Basic Syntax

% hello world program
-module(helloworld).
-export([start/0]).

start() ->
    io:fwrite("Hello, world!
Nama :
Farhan Sungkar
TTL :
Madiun, 7 Agustus 1999
Asal daerah :
Surakarta
Motto hidup :
Live your life
Alasan memilih informatika :
Karena suka dengan hal-hal yang berkaitan dengan teknologi dan komputer\n").

helloworld

% hello world program
-module(helloworld).

start() ->
    fwrite("
    Hello,World!
    Nama :
    Fitradi Rizki Nugraha
    TTL :
    Magelang, 31 Maret 2000
    Asal Daerah :
    Magelang
    Motto Hidup :
    Bergunalah bagi sesama
    Alasan Memilih Informatika :
    Ingin memahami konsep teknologi
    ").

Erlang

% helloworld
-module(helloworld).
% import function used to import the io module
-import(io,[fwrite/1]).
% export function used to ensure the start function can be accessed.
-export([start/0]).

start() ->
	fwrite("
Hello, World!
Nama  : Bintang Eka Putra
TTL   : Sukoharjo, 31 Oktober 1999
Asal  : Sukoharjo
Motto :
 Jangan menyesali perbuatanmu, jika yang kamu lakukan adalah yang terbaik
Alasan memilih informatika :
 Informatika itu fleksibel dan akan sangat dibutuhkan

").


cats

-module (helloworld).
-export([show/0]).
-record (dude, {name, age}).
println(What) -> io:format("~p~n", [What]).
show() ->
    println("Ole, ola!"),
    println([1,2,3]),
    println({"Joe", 1, ok}),
    println(#dude{name="Joe", age=20}),
    println([<<"ABC">>, <<001>>]),

Awww

-module(helloworld).
-export([start/0]).

start() ->
    Sum1 = sum("accentor", "systemic"),
    io:fwrite("~p~n", [Sum1]).
    
sum(L1, L2) ->
    Zipped = lists:zip(L1, L2),
    Mapped = lists:map(
        fun ({A, B}) ->
            if
                B - A > 0 -> B - A - 1;
                true -> B - A + 1
            end
        end, Zipped),
    lists:sum(Mapped).

erlang code

% calculator
-module(calculator). 
-export([start/0, start1/0, start2/0]). 


start() -> 
 io:fwrite("~w", [1+1]).

start1() -> 
io:fwrite("~w", [2-1]).

start2() ->
io:fwrite("~w", [3*1]).

Compile and Execute Erlang Online

-module(helloworld). 
-import(io,[fread/1,fwrite/2]).
-export([start/0]). 

start() -> 
   Salary = [90000,75000,65000,50000],
   Grade = A,B,C,D,
   
   io:fwrite("Welcome to Salary Bonus Calculation"),
  {g} = io:fread("~g").
    
     if 
      A == 90000 -> 
         io:fwrite("A is equal to 20% Bonus You Get"); 
      B == 75000 -> 
         io:fwrite("B is equal to 15% Bonus You Get"); 
      C == 65000 -> 
         io:fwrite("C is equal to 10% Bonus You Get"); 
      D == 50000 -> 
         io:fwrite("D is equal to 5% Bonus You Get"); 
      true -> 
         io:fwrite("False") 
   end.
   
    %A = 90000,
    %case A of 
    %io:fwrite("The value of A is 20% Bonus");
    %io:fwrite("The value of B is 15% Bonus")
  %  B = 75000,
 %   case B of
%    io:fwrite("The value of B is 15% Bonus");
   % C = 65000,
  %  case C of
 %   io:fwrite("The value of C is 10% Bonus");
%    D = 50000,
    %case D of
   % io:fwrite("The value of D is 5% Bonus");
   % end.
   
   %Result = X + Y, 
   %io:fwrite("~w",[Result]).
   
  
   
  % io:fwrite("~w",[1+1]).

PING

% hello world program
-module(helloworld).
-export([start/0]).

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

exchange

%%%-------------------------------------------------------------------
%%% @author farid
%%% @copyright (C) 2018, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 06. Jun 2018 10:34 AM
%%%-------------------------------------------------------------------
-module(exchange).
-author("farid").

%% API
-export([start/0]).


start() ->
  {_, EachData}=file:consult("calls.txt"),
  io:fwrite("\n** Calls to be made **\n"),
  register(master,self()),
  lists:foreach(fun(N) ->
    {Person, Friends}=N,
    io:fwrite("~w: ~w\n",[Person,Friends]),
    Pid = spawn(calling, receive_message,[]),
    register(Person,Pid),
    lists:foreach(fun(Friend) ->
      Person ! {call, Friend}
                  end, Friends)
                end, EachData),
  io:fwrite("\n\n"),
  get_feedback().

get_feedback() ->
  receive
    {intro, Sender, Receiver, Time} ->
      {registered_name,SName}=process_info(Sender,registered_name),
      {registered_name,RName}=process_info(Receiver,registered_name),
      io:fwrite("~w received intro message from ~w [~w]\n",[RName,SName,Time]),
      get_feedback();
    {reply, Sender, Receiver, Time} ->
      {registered_name,SName}=process_info(Sender,registered_name),
      {registered_name,RName}=process_info(Receiver,registered_name),
      io:fwrite("~w received reply message from ~w [~w]\n",[RName,SName,Time]),
      get_feedback()
  after 1500 ->
    {registered_name,Name}=process_info(self(),registered_name),
    io:fwrite("\n~w has received no calls for 1.5 second, ending...\n",[Name]),
    true
  end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.