Skip to content

Instantly share code, notes, and snippets.

@schmalz
Created October 11, 2020 16:45
Show Gist options
  • Save schmalz/0cea1602ff68c6bbf832bcbde1932666 to your computer and use it in GitHub Desktop.
Save schmalz/0cea1602ff68c6bbf832bcbde1932666 to your computer and use it in GitHub Desktop.
LFE tutorial 20 - registered process names
(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