Compare commits

..

3 commits

4 changed files with 13 additions and 12 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.info 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.info 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,9 +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 f end quote bind_quoted: [names: names, fields: fields] do
quote do Enum.zip(names, fields) |> Map.new
Enum.zip(unquote(names), unquote(fields))
end end
end end
end end

View file

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