From 05e31c1d68dbe7e35482213e4a56945ad2f56b85 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 12 Oct 2026 16:45:54 +0200 Subject: [PATCH] csys: use new gen-proc also in test and environ code --- csys/csys.lisp | 21 ++++++++------------- csys/environ.lisp | 9 +++------ test/test-csys.lisp | 13 +++++++------ util/util.lisp | 2 +- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/csys/csys.lisp b/csys/csys.lisp index 5a466a7..68525f1 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -12,7 +12,7 @@ #:scope #:environ #:make-program #:create-zero #:neuron #:gen-proc #:std-proc #:eff-proc - #:handle-action #:basic-actions #:forward #:notify + #:basic-actions #:forward #:notify #:no-op #:printer #:value-add #:create #:connect #:modify-value #:add #:multiply #:send-message #:send-create #:send-connect #:send-switch)) @@ -118,27 +118,22 @@ (defun std-proc (&rest args &key actions &allow-other-keys) (let ((actions (or actions (merge-actions args)))) (gen-proc actions - :after (lambda (msg scope) (forward msg scope) msg)))) + :after (lambda (msg scope) (forward msg scope))))) (defun eff-proc (&rest args &key actions &allow-other-keys) (let ((actions (or actions (merge-actions args)))) (flet ((forward-eff (msg scope) - (when msg - (setf (nth 1 (shape:head msg)) :effect) - (forward msg scope) - (unless (syns scope) (notify msg scope))) - msg)) + (when msg + (setf (nth 1 (shape:head msg)) :effect) + (forward msg scope) + (unless (syns scope) (notify msg scope))))) (gen-proc actions :after #'forward-eff)))) -(defun handle-action (msg scope &key (default (no-op)) actions) - (let* ((key (message:action msg)) - (act (getf actions key (getf actions :default default)))) - (funcall act msg scope))) - (defun forward (msg scope) (when msg (dolist (s (syns scope)) - (funcall s msg)))) + (funcall s msg))) + msg) (defun notify (msg scope) (setf (actor:customer msg) actor:*self*) diff --git a/csys/environ.lisp b/csys/environ.lisp index 0e3d014..aa0d9b7 100644 --- a/csys/environ.lisp +++ b/csys/environ.lisp @@ -32,18 +32,15 @@ (defun simple-setup (cfg) (destructuring-bind (prg &key std contacts) cfg - (let* ((env (create #'simple-proc (csys:printer) :contacts contacts)) + (let* ((env (create (simple-proc) (csys:printer) :contacts contacts)) (zero-val (getf std :bias 0)) (zero-cat (getf std :cat :c00))) (csys:create-zero prg env :categ (list csys:*domain* zero-cat) :value zero-val) env))) (defun simple-proc (msg scope) - (util:mv-bind (nmsg (scope scope)) - (csys:handle-action msg scope :actions (actions)) - (util:lgi msg nmsg) - (when nmsg - (actor:send (csys:environ scope) nmsg)))) + (csys:gen-proc (actions) + :after (lambda (msg scope) (actor:send (csys:environ scope) msg)))) ;;;; eff contact cells diff --git a/test/test-csys.lisp b/test/test-csys.lisp index 6ce2b48..aa810b3 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -41,12 +41,13 @@ (config:add-action '(:csys) #'tc:collect)) (defun proc-env (msg scope) - (let ((t:*test-suite* (csys:environ scope))) - (util:mv-bind (nmsg (scope scope)) - (csys:handle-action msg scope :actions (environ:actions)) - (util:lgi msg nmsg) - (when nmsg - (actor:send (core:mailbox (tc:receiver t:*test-suite*)) nmsg))))) + (let* ((t:*test-suite* (csys:environ scope)) + (proc + (csys:gen-proc (environ:actions) + :after (lambda (msg scope) + (when msg + (actor:send (core:mailbox (tc:receiver t:*test-suite*)) msg)))))) + (funcall proc msg scope))) (defun run () (let ((t:*test-suite* (make-instance 'tc:test-suite :name "csys"))) diff --git a/util/util.lisp b/util/util.lisp index fb30dc7..6c49264 100644 --- a/util/util.lisp +++ b/util/util.lisp @@ -99,7 +99,7 @@ `(setf ,pl (cons ,k (cons ,v ,pl)))) (defmacro mv-bind (vars vform &body body) - `(destructuring-bind ,(cons (car vars) (cons '&optional (cdr vars))) + `(destructuring-bind ,(cons '&optional (cons (car vars) (cdr vars))) (multiple-value-list ,vform) ,@body)) (defun with-iterator (it fn)