diff --git a/lib/csys/csys.ex b/lib/csys/csys.ex index a54facb..013b476 100644 --- a/lib/csys/csys.ex +++ b/lib/csys/csys.ex @@ -12,24 +12,34 @@ defmodule Scopes.CSys do # predefined neuron processors def process(msg, scope) do - hd(elem(scope, 1)).(msg, scope) + proc(scope).(msg, scope) end - def echo(msg, {_state, _code, _syns, env}) do - send(env, msg) + def echo(msg, scope) do + send(env(scope), msg) end - def forward(msg, {_state, _code, syns, _env}) do - Enum.reduce(syns, false, fn s, _acc -> s.(msg); true end) + def forward(msg, scope) do + Enum.reduce(syns(scope), false, fn s, _acc -> s.(msg) end) end - def std_proc({:parent}, {_state, _code, _syns, env}) do + def std_proc({:parent}, scope) do syn = synapse(self(), &Function.identity/1) - new = neuron({[], [&std_proc/2], [syn], env}) - send(env, {:created, new}) + new = neuron({[], [&std_proc/2], [syn], env(scope)}) + # send(env(scope), {:created, new}) + echo({:created, new}, scope) end def std_proc(msg, scope) do unless forward(msg, scope), do: echo(msg, scope) end + + # helper functions + + def proc(scope), do: hd(code(scope)) + + def state(scope), do: elem(scope, 0) + def code(scope), do: elem(scope, 1) + def syns(scope), do: elem(scope, 2) + def env(scope), do: elem(scope, 3) end