Created
July 16, 2019 10:53
-
-
Save mietek/9043c54daa6771441393034a070acb79 to your computer and use it in GitHub Desktop.
Erlang is magic!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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