csys: minor improvements: qualified import, logging, send with optional delay

This commit is contained in:
Helmut Merz 2026-04-25 17:13:01 +02:00
parent e793e590c2
commit 1c3be4a0e7
3 changed files with 20 additions and 18 deletions

View file

@ -1,18 +1,16 @@
defmodule Scopes.Core.Actor do defmodule Scopes.Core.Actor do
require Logger
defp loop(bhv) do defp loop(bhv) do
receive do receive do
msg -> msg ->
# IO.puts("receive: #{inspect msg}") Logger.debug([msg: inspect(msg)])
case msg do case msg do
{:message, msg} -> {:message, msg} ->
bhv.(msg) bhv.(msg)
loop(bhv) loop(bhv)
{:become, bhv_n} -> loop(bhv_n)
{:become, bhv_n} -> {:quit} -> nil
loop(bhv_n)
{:quit} ->
nil
end end
end end
end end
@ -21,7 +19,9 @@ defmodule Scopes.Core.Actor do
spawn_link(fn -> loop(bhv) end) spawn_link(fn -> loop(bhv) end)
end end
def send(ac, msg) do def send(ac, msg, delay \\ 0) do
Process.sleep(delay)
#Process.send_after(ac, {:message, msg}, delay)
Kernel.send(ac, {:message, msg}) Kernel.send(ac, {:message, msg})
end end

View file

@ -12,16 +12,16 @@ defmodule Scopes.CSys do
Actor.become(self(), fn msg -> process(msg, scope) end) Actor.become(self(), fn msg -> process(msg, scope) end)
end end
def synapse(rcvr, op) do def synapse(rcvr, op, delay \\ 0) do
fn msg -> Actor.send(rcvr, op.(msg)) end fn msg -> Actor.send(rcvr, op.(msg), delay) end
end
def process(msg, scope) do
proc(scope).(msg, scope)
end end
# helper functions # helper functions
defp process(msg, scope) do
proc(scope).(msg, scope)
end
def state(scope), do: elem(scope, 0) def state(scope), do: elem(scope, 0)
def proc(scope), do: elem(scope, 1) def proc(scope), do: elem(scope, 1)
def syns(scope), do: elem(scope, 2) def syns(scope), do: elem(scope, 2)

View file

@ -1,7 +1,9 @@
defmodule Scopes.CSys.Programs do defmodule Scopes.CSys.Programs do
import Scopes.CSys import Scopes.CSys, only: [
neuron: 1, update_neuron: 1, synapse: 3,
syns: 1, env: 1
]
alias Scopes.CSys
alias Scopes.CSys.Environ alias Scopes.CSys.Environ
# programs # programs
@ -23,7 +25,7 @@ defmodule Scopes.CSys.Programs do
def std_proc({:parent}, scope) do def std_proc({:parent}, scope) do
env = env(scope) env = env(scope)
syn = synapse(self(), &Function.identity/1) syn = synapse(self(), &Function.identity/1, 0)
new = neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env}) new = neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env})
notify({:created, new}, scope) notify({:created, new}, scope)
end end
@ -33,7 +35,7 @@ defmodule Scopes.CSys.Programs do
#proc = Environ.get_next_stage(env, :basic, :initial) #proc = Environ.get_next_stage(env, :basic, :initial)
#proc = Environ.get_stage_for(env, :basic, :activate) #proc = Environ.get_stage_for(env, :basic, :activate)
proc = Environ.get_stage(env, :basic, :active) proc = Environ.get_stage(env, :basic, :active)
CSys.update_neuron({state, proc, syns, env}) update_neuron({state, proc, syns, env})
end end
def std_proc(msg, scope) do def std_proc(msg, scope) do