macro Util.show: renamed, use in CSys for logging; remove lgi

This commit is contained in:
Helmut Merz 2026-06-07 09:01:13 +02:00
parent 88d6544749
commit 7a73d32752
4 changed files with 9 additions and 15 deletions

View file

@ -1,11 +1,13 @@
defmodule Scopes.CSys do defmodule Scopes.CSys do
require Logger require Logger
require Scopes.Util
alias Scopes.Core.Actor alias Scopes.Core.Actor
alias Scopes.Shape alias Scopes.Shape
alias Scopes.Util
def neuron(scope) do def neuron(scope) do
#Logger.info([scope: inspect(scope)]) #Logger.info(Util.show [scope])
Actor.create(fn msg -> process(msg, scope) end) Actor.create(fn msg -> process(msg, scope) end)
end end
@ -58,7 +60,7 @@ defmodule Scopes.CSys do
# send shortcuts # send shortcuts
def send_message(rcvr, head, data \\ %{}) do def send_message(rcvr, head, data \\ %{}) do
Logger.debug rcvr: inspect(rcvr), head: inspect(head), data: inspect(data) Logger.debug(Util.show [rcvr, head, data])
Actor.send(rcvr, Shape.create(head, data: data)) Actor.send(rcvr, Shape.create(head, data: data))
end end

View file

@ -1,9 +1,11 @@
defmodule Scopes.CSys.Program do defmodule Scopes.CSys.Program do
require Logger require Logger
require Scopes.Util
alias Scopes.CSys alias Scopes.CSys
alias Scopes.CSys.Environ alias Scopes.CSys.Environ
alias Scopes.Shape alias Scopes.Shape
alias Scopes.Util
defmodule State do defmodule State do
defstruct [:value, :count, :stage, :prog] defstruct [:value, :count, :stage, :prog]
@ -74,7 +76,7 @@ defmodule Scopes.CSys.Program do
limit = args[:limit] limit = args[:limit]
data = Shape.data(msg) data = Shape.data(msg)
state = CSys.state(scope) state = CSys.state(scope)
Logger.debug data: data, state_value: state.value, threshold: threshold, self: self() Logger.debug(Util.show [data, state.value, threshold, self()])
value_n = state.value + data.value value_n = state.value + data.value
if value_n >= threshold do if value_n >= threshold do
value_out = limit && rem(value_n - 1, limit) + limit || value_n value_out = limit && rem(value_n - 1, limit) + limit || value_n

View file

@ -1,17 +1,8 @@
defmodule Scopes.Util do defmodule Scopes.Util do
defmacro show(fields) do
defmacro fields_info(fields) do
names = for f <- fields do Macro.to_string(f) end names = for f <- fields do Macro.to_string(f) end
quote bind_quoted: [names: names, fields: fields] do quote bind_quoted: [names: names, fields: fields] do
Enum.zip(names, fields) |> Map.new Enum.zip(names, fields) |> Map.new
end end
end end
defmacro lgi(fields) do
#IO.inspect(fields)
quote do
require Logger
Logger.info(Scopes.Util.fields_info(unquote(fields)))
end
end
end end

View file

@ -7,8 +7,7 @@ defmodule Scopes.UtilTest do
describe "info:" do describe "info:" do
test "fields" do test "fields" do
{a, b, c} = {17, 22, 42} {a, b, c} = {17, 22, 42}
assert %{"a" => 17, "b" => 22, "c" => 42} = Util.fields_info([a, b, c]) assert %{"a" => 17, "b" => 22, "c" => 42} = Util.show([a, b, c])
Util.lgi([a, b, c])
end end
end end
end end