From 42195f0cefb31989e9ec9545986b7c41e1a586fd Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 24 Jul 2026 19:54:35 +0200 Subject: [PATCH] csys action handlers: always defined as closures; + some minor clean-ups and rearrangements --- csys/csys.lisp | 46 ++++++++++++++++++++++----------------------- csys/environ.lisp | 4 ++-- test/test-csys.lisp | 5 ++--- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/csys/csys.lisp b/csys/csys.lisp index bfc4ec4..f462959 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -53,8 +53,9 @@ (let* ((domain (car categ)) (addr (list domain (cadr categ) name)) (msg (message:create (list domain :create) :data (list :addr addr))) - (scope (scope prg env :categ categ))) - (create msg scope))) + (scope (scope prg env :categ categ)) + (zero (neuron scope))) + (notify-created msg zero scope))) ;;;; neurons (= async tasks) and synapses (= connections) @@ -73,7 +74,7 @@ (defun process (scope) (lambda (msg) (funcall (proc scope) msg scope))) -(defun std-proc (msg scope &key (default #'remember) params actions) +(defun std-proc (msg scope &key (default (remember)) actions params) (util:mv-bind (nmsg (nscope scope)) (handle-action msg scope :default default :actions actions :params params) (when nmsg (forward nmsg (syns nscope))) @@ -86,37 +87,36 @@ (when nmsg (notify nmsg nscope)) (update nscope))) -(defun create (msg scope) - (let ((new (neuron (apply #'reset-scope scope (shape:data msg))))) - (notify-created msg new scope))) - -(defun do-log (msg scope) - (util:lgi msg)) - -(defun notify (msg scope) - (actor:send (environ scope) msg)) - -(defun forward (msg syns) - (dolist (s syns) - (funcall s msg))) - (defun handle-action (msg scope &key (default (no-op)) actions params) (let* ((key (message:action msg)) (act (getf actions key (getf actions :default default)))) (apply act msg scope params))) +(defun forward (msg syns) + (dolist (s syns) + (funcall s msg))) + +(defun notify (msg scope) + (actor:send (environ scope) msg)) + (defun notify-created (msg new scope) (let* ((head (list (message:domain msg) :created)) (data (util:plist-merge (shape:data msg) `(:new ,new :parent ,actor:*self*))) (msg1 (message:create head :data data))) (notify msg1 scope))) -;;;; predefined neuron actions +;;;; action handlers -(defun no-op (&key stop) +(defun no-op (&key no-forward) (lambda (msg scope) - (unless stop msg))) + (unless no-forward msg))) -(defun remember (msg scope) - (setf (value scope) (shape:data-value msg :value)) - (values msg scope)) +(defun remember () + (lambda (msg scope) + (setf (value scope) (shape:data-value msg :value)) + (values msg scope))) + +(defun create () + (lambda (msg scope) + (let ((new (neuron (apply #'reset-scope scope (shape:data msg))))) + (notify-created msg new scope)))) diff --git a/csys/environ.lisp b/csys/environ.lisp index 39b31e1..73d564e 100644 --- a/csys/environ.lisp +++ b/csys/environ.lisp @@ -21,14 +21,14 @@ (let ((prg (csys:make-program proc))) (csys:neuron (csys:scope prg meta-env :cls 'scope :categ '(:env :c00))))) -;;;; action handlers, public callables +;;;; action handlers (defun actions () (list :created #'cell-created :notify (csys:no-op) :effect (csys:no-op) :value #'forward - :default (csys:no-op :stop t))) + :default (csys:no-op :no-forward t))) (defun cell-created (msg scope) (let* ((data (shape:data msg)) diff --git a/test/test-csys.lisp b/test/test-csys.lisp index 3d9081c..02d42b0 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -31,8 +31,7 @@ (config:add :test-receiver :setup #'tc:setup) ;(config:add-action '(:csys :effect :c00 "0-0") (value-in '(1))) (config:add-action '(:csys :effect) #'tc:check-message) - (config:add-action '(:csys) (constantly nil)) - ) + (config:add-action '(:csys) (constantly nil))) (defun proc-env (msg scope) (let ((t:*test-suite* (csys:environ scope))) @@ -60,12 +59,12 @@ (let* ((recv (core:find-service :test-receiver)) (env (environ:create #'proc-env t:*test-suite*))) (setf (tc:receiver t:*test-suite*) recv) - ;(csys:create-zero (test-program) env) (csys:create-zero prg env) env)) (deftest test-basic-0 () (let ((env (setup-test (csys:make-program #'csys:eff-proc))) + ;(env (setup-test (test-program)) (rcvr (tc:receiver t:*test-suite*))) (sleep 0.1) (tc:expect rcvr (message:create '(:csys :effect :c00 "0-0") :data '(:value 1)))