Created
October 11, 2020 16:45
-
-
Save schmalz/0cea1602ff68c6bbf832bcbde1932666 to your computer and use it in GitHub Desktop.
LFE tutorial 20 - registered process names
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
(defmodule lfe-tut-20 | |
(export (start 0) | |
(ping 1) | |
(pong 0))) | |
(defun ping | |
([0] | |
(! 'pong 'finished) | |
(lfe_io:format "ping finished~n" ())) | |
([n] | |
(! 'pong (tuple 'ping (self))) | |
(receive | |
('pong | |
(lfe_io:format "ping received pong~n" ()))) | |
(ping (- n 1)))) | |
(defun pong [] | |
(receive | |
('finished | |
(lfe_io:format "pong received finished, pong finished~n" ())) | |
((tuple 'ping ping-pid) | |
(lfe_io:format "pong received ping~n" ()) | |
(! ping-pid 'pong) | |
(pong)))) | |
(defun start [] | |
(let ((pong-pid (spawn 'lfe-tut-20 'pong ()))) | |
(register 'pong pong-pid) | |
(spawn 'lfe-tut-20 'ping '(3)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment