diff --git a/csys/csys.lisp b/csys/csys.lisp index a1dddc4..1070baa 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -13,11 +13,11 @@ (:export #:environment #:*environment* #:actions #:set-action #:send #:send-message #:*sensors* #:neuron #:synapse - #:logger)) + #:std-proc)) (in-package :scopes/csys) -;;;; environment: common information, with list of generally available actions +;;;; environment: common information, with list of globally available actions (defclass environment () ((actions :reader actions :initarg :actions :initform (make-hash-table)))) @@ -69,17 +69,24 @@ ;;;; predefined neuron processors and helper / utility funtions -(defun logger (msg state syns env) +(defun std-proc (msg state syns env) (util:lgi msg state) - (destructuring-bind (msg state syns) (handle-action msg state syns env) - (forward msg syns) - (actor:become (neuron #'logger (shape:data msg) syns env)))) + (destructuring-bind (nmsg nst syns) + (handle-action msg state syns env :default #'remember) + (forward nmsg syns) + (actor:become (neuron #'std-proc nst syns env)))) (defun forward (msg syns) (dolist (s syns) (funcall s msg))) -(defun handle-action (msg state syns env) - (let ((act (action env (shape:head-value msg :action)))) +(defun handle-action (msg state syns env &key default) + (let ((act (or (action env (shape:head-value msg :action)) default))) (or (and act (funcall act msg state syns env)) (list msg state syns)))) + +;;;; predefined neuron actions + +(defun remember (msg state syns env) + (list msg (shape:data msg) syns)) + diff --git a/test/etc/config-csys.lisp b/test/etc/config-csys.lisp index db0b307..2bcc90a 100644 --- a/test/etc/config-csys.lisp +++ b/test/etc/config-csys.lisp @@ -4,8 +4,8 @@ (config:root) -(config:add-action '(:csys :sensor :log) - (csys:neuron #'csys:logger :testing +(config:add-action '(:csys :sensor :std) + (csys:neuron #'csys:std-proc 0 (list (csys:synapse *probe*)) )) @@ -14,4 +14,3 @@ :logfile (t:test-path "scopes-test.log" "log") :console nil) - diff --git a/test/test-csys.lisp b/test/test-csys.lisp index c43906b..4e68852 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -30,6 +30,9 @@ (defvar *probe* nil) +(defun add (msg state syns env) + (list msg (+ (shape:data msg) state) syns env)) + ;;;; test runner (defun run () @@ -49,8 +52,8 @@ (t:show-result)))) (deftest test-basic () - (csys:send-message '(:csys :add :log :s1) 1) - (csys:send-message '(:csys :add :log :s1) 3) - (csys:send-message '(:csys :sub :log :s2) 4) - (csys:send-message '(:csys :add :log :s2) 5) + (csys:send-message '(:csys :add :std :s1) 1) + (csys:send-message '(:csys :add :std :s1) 3) + (csys:send-message '(:csys :sub :std :s2) 4) + (csys:send-message '(:csys :add :std :s2) 5) )