ex-scopes/lib/csys/programs.ex

32 lines
646 B
Elixir

defmodule Scopes.CSys.Programs do
import Scopes.CSys
alias Scopes.CSys.Environ
# programs
def basic_prog() do
[&std_proc/2]
end
# processors
def notify(msg, scope) do
Environ.notify(env(scope), msg)
end
def forward(msg, scope) do
Enum.reduce(syns(scope), false, fn s, _acc -> s.(msg); true end)
end
def std_proc({:parent}, scope) do
env = env(scope)
syn = synapse(self(), &Function.identity/1)
new = neuron({[], Environ.get_prog(env, :basic), [syn], env})
notify({:created, new}, scope)
end
def std_proc(msg, scope) do
unless forward(msg, scope), do: notify(msg, scope)
end
end