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
(defparameter *player-health* NIL) | |
(defparameter *player-agility* NIL) | |
(defparameter *player-strength* NIL) | |
(defparameter *monsters* NIL) | |
(defparameter *monster-builders* NIL) | |
(defparameter *monster-count* 12) | |
(defun randval (n) | |
"A random number between one and `N`. The number returned is guaranteed to be greater than or equal to one." |
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
(defparameter *max-label-length* 30) | |
(defun dot-label (exp) | |
"Produce a DOT label from a Lisp `exp`." | |
(if exp | |
(let ((s (write-to-string exp :pretty nil))) | |
(if (> (length s) *max-label-length*) | |
(concatenate 'string (subseq s 0 (- *max-label-length* 3)) "...") | |
s)) | |
"")) |
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 Todo.Cache do | |
use GenServer | |
@moduledoc """ | |
A todo-list cache; maps todo-list names to their corresponding server PIDs. | |
""" | |
# Client API | |
@doc """ |
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 Sup do | |
def start(name, child_spec_list) do | |
Process.register(pid = spawn(__MODULE__, :init, [child_spec_list]), name) | |
{:ok, pid} | |
end | |
def stop(name), do: send(name, :stop) | |
def init(child_spec_list) do |
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 PhoneFSM do | |
@behaviour :gen_statem | |
@moduledoc """ | |
A mobile 'phone controller. | |
""" | |
# Client API | |
def start_link(ms), do: :gen_statem.start_link(__MODULE__, ms, []) |
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 Coffee do | |
use GenStateMachine, callback_mode: :state_functions | |
# Client API | |
def start_link() do | |
GenStateMachine.start_link(__MODULE__, {}, [name: __MODULE__]) | |
end | |
def stop() do |
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 Frequency do | |
use GenServer | |
@moduledoc""" | |
Maintain a list of available radio frequencies and any associations between process identifiers and their | |
allocated frequencies. | |
""" | |
@initial_allocations [] | |
@initial_frequencies [10, 11, 12, 13, 14, 15] |
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 Frequency do | |
@moduledoc""" | |
""" | |
# Client API | |
def start() do | |
Process.register(Process.spawn(&init/0, []), :frequency) | |
end |
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 HLR do | |
@moduledoc""" | |
Maintain the associations between Mobile Subscriber Integrated Services Digital Network (MSISDN) numbers and process | |
identifiers (PID). | |
""" | |
def new() do | |
:ets.new(:msisdn_pid, [:named_table]) | |
:ets.new(:pid_msisdn, [:named_table]) |