An LFE/OTP application for running Port examples in various languages
This application assumes that the following are on your system:
git
- GNU
make
- A modern install of Erlang (v20+)
- rebar3 (Erlang build tool)
- Golang
- SBCL (Steel Bank Common Lisp)
- Quicklisp
This project's rebar.config.script
will set the required Go environment
variables, but you will need to link the Common Lisp examples to your local
Quicklisp directory:
cd apps/ports/priv/cl-ports-example/
ln -s `pwd` ~/quicklisp/local-projects/
cd -
Or you can run this convenience make
target instead:
make quicklisp-link
make
This will build the Go and Common Lisp servers that are used in the examples, compile the LFE, and create an OTP release.
Now the app is ready to run:
make run
This will put you into a release console running the Erlang shell. Switch to LFE with the following:
1> lfe_shell:start().
See the running gen_server
s for Go and CL:
lfe> (ports.app:children)
(#(ports.lisp.server #Pid<0.366.0> worker (ports.lisp.server))
#(ports.go.server #Pid<0.365.0> worker (ports.go.server)))
(ports.go.server:send #(command echo))
#(result "echo")
(ports.lisp.server:send #(command echo))
#(result "echo")
You can induce a crash in the Go and Common Lisp echo servers. To easily see that a new port gets started up, let's take a look at the server PIDs and port IDs:
(ports@spacemac)lfe> (ports.app:servers)
(#(go #Pid<0.356.0>) #(lisp #Pid<0.357.0>))
(ports@spacemac)lfe> (ports.app:ports)
(#(go #Port<0.7>) #(lisp #Port<0.8>))
Now let's crash things:
(ports@spacemac)lfe> (ports.go.server:send #(command crash_it))
(ports@spacemac)lfe> (ports.lisp.server:send #(command crash_it))
Let's confirm that there are now new servers and ports created:
(ports@spacemac)lfe> (ports.app:servers)
(#(go #Pid<0.382.0>) #(lisp #Pid<0.385.0>))
(ports@spacemac)lfe> (ports.app:ports)
(#(go #Port<0.10>) #(lisp #Port<0.11>))