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).


create_dlist(0) -> [];
create_dlist(N) ->
    [spwan(?Moduele, dlist, [0])] ||  _ <- list:seq(1,N).
    
dlist(V) ->
    receive
        {get, P} ->
            P ! V,
            dlist(V);
        {set, P} -> dlist(V)
    end.

dlist_to_list([], L) -> L;
dlist_to_list([P|Ps], L) ->
    P ! {get, self()},
    receive
        V ->
            dlist_to_list(Ps, L ++ [V])
    end.

dmap([], _) -> ok;
dmap(F, Fun) ->
    P ! {get, self()},
    receive
        V -> P ! {set, Fun(V)}
    end
    
dmap([P|Ps], Fun) ->
    P ! {get, self()},
    receive
        V -> P ! {set, Fun(V)]
    end
    dmap(Ps, Fun).
    
    
    

Advertisements
Loading...

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