% hello world program -module(helloworld). -export([start/0]). start() -> io:fwrite("Hello, world!\n"). 2+4.
-module(basic). -export([id/1]). % need to name arity, just as in Prolog %% identity function: id(Anything) -> Anything.
% hello world program -module(helloworld). -export([start/0]). start() -> io:fwrite("Hello, world!\n").
-module(helloworld). -export([start/0]). start() -> Fn = fun() -> io:fwrite("Anonymous Function") end, Fn().
-module(helloworld). -export([max/1,start/0]). max(N) -> Max = erlang:system_info(process_limit), io:format("Maximum allowed processes:~p~n" ,[Max]), statistics(runtime), statistics(wall_clock), L = for(1, N, fun() -> spawn(fun() -> wait() end) end), {_, Time1} = statistics(runtime), {_, Time2} = statistics(wall_clock), lists:foreach(fun(Pid) -> Pid ! die end, L), U1 = Time1 * 1000 / N, U2 = Time2 * 1000 / N, io:format("Process spawn time=~p (~p) microseconds~n" , [U1, U2]). wait() -> receive die -> void end. for(N, N, F) -> [F()]; for(I, N, F) -> [F()|for(I+1, N, F)]. start()-> max(1000), max(100000).
-module(helloworld). -export([loop/0,start/0]). loop() -> receive {rectangle, Width, Ht} -> io:fwrite("Area of rectangle is ~p~n" ,[Width * Ht]), loop(); {circle, R} -> io:fwrite("Area of circle is ~p~n" , [3.14159 * R * R]), loop(); Other -> io:fwrite("Unknown"), loop() end. start() -> Pid = spawn(fun() -> loop() end), Pid ! {rectangle, 6, 10}.
-module(helloworld). -export([start/0]). start() -> Pid = spawn(fun() -> server("Hello") end), Pid ! {hello}. server(Message) -> io:fwrite("~p",[Message]).
-module(helloworld). -export([start/0]). start() -> spawn(fun() -> server("Hello") end). server(Message) -> io:fwrite("~p",[Message]).
-module(helloworld). -export([start/0]). start() -> spawn_link(node(),fun() -> server("Hello") end). server(Message) -> io:fwrite("~p",[Message]).
-module(helloworld). -export([start/0]). start() -> io:fwrite("~p",[is_alive()]).
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more