Skip to content

Instantly share code, notes, and snippets.

@mietek
Created July 16, 2019 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mietek/9043c54daa6771441393034a070acb79 to your computer and use it in GitHub Desktop.
Save mietek/9043c54daa6771441393034a070acb79 to your computer and use it in GitHub Desktop.
Erlang is magic!
-module(magic).
-export([loop/0, start/0]).
loop() ->
receive
Fun ->
Fun(),
loop()
end.
greet() ->
io:format("Hello, world!~n").
start() ->
To = spawn(magic, loop, []),
To ! fun greet/0,
To ! fun() -> io:format("Erlang is magic!~n") end,
ok.
% $ erl
% Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
% Eshell V10.4.3 (abort with ^G)
% 1> c("magic.erl").
% {ok,magic}
% 2> magic:start().
% Hello, world!
% ok
% Erlang is magic!
% 3>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment