csys: + gen-proc: generic neuron proc, handling composition of actions

This commit is contained in:
Helmut Merz 2026-10-12 07:54:12 +02:00
parent cb638be671
commit 38c7912bb8
4 changed files with 34 additions and 23 deletions

View file

@ -11,7 +11,7 @@
(:export #:*domain*
#:scope #:environ
#:make-program #:create-zero
#:neuron #:std-proc #:eff-proc
#:neuron #:gen-proc #:std-proc #:eff-proc
#:handle-action #:basic-actions #:forward #:notify
#:no-op #:printer #:value-add #:create #:connect
#:modify-value #:add #:multiply
@ -105,33 +105,40 @@
(defun merge-actions (&optional act+ (base (basic-actions)))
(util:plist-merge base act+))
(defun gen-proc (actions &key default before after)
(lambda (msg scope)
(let* ((key (message:action msg))
(acts (getf actions key (getf actions :default default))))
(dolist (act (alx:flatten (cons before (cons acts (list after)))))
(when act
(util:mv-bind (nmsg (nscope scope)) (funcall act msg scope)
(setf msg nmsg scope nscope)))))
(update scope)))
(defun std-proc (&rest args &key actions &allow-other-keys)
(let ((actions (or actions (merge-actions args))))
(lambda (msg scope)
(util:mv-bind (nmsg (nscope scope))
(handle-action msg scope :actions actions)
(when nmsg (forward nmsg (syns nscope)))
(update nscope)))))
(gen-proc actions
:after (lambda (msg scope) (forward msg scope) msg))))
(defun eff-proc (&rest args &key actions &allow-other-keys)
(let ((actions (or actions (merge-actions args))))
(lambda (msg scope)
(util:mv-bind (nmsg (nscope scope))
(handle-action msg scope :default (no-op) :actions actions)
(when nmsg
(setf (nth 1 (shape:head nmsg)) :effect)
(forward nmsg (syns nscope))
(unless (syns nscope) (notify nmsg nscope)))
(update nscope)))))
(flet ((forward-eff (msg scope)
(when msg
(setf (nth 1 (shape:head msg)) :effect)
(forward msg scope)
(unless (syns scope) (notify msg scope)))
msg))
(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 syns)
(dolist (s syns)
(funcall s msg)))
(defun forward (msg scope)
(when msg
(dolist (s (syns scope))
(funcall s msg))))
(defun notify (msg scope)
(setf (actor:customer msg) actor:*self*)

View file

@ -138,7 +138,7 @@
(env *env*) &allow-other-keys)
(let ((head (list domain :create)))
(when (listp rcvr)
(setf head (append head (cdr rcvr)))
(setf head (append head rcvr))
(setf rcvr nil))
(setf args (alx:remove-from-plist args :domain :env))
(send-message head args :customer rcvr :env env)))

View file

@ -102,10 +102,14 @@
(let ((pl '(:a 0)))
(== (util:plist-add pl :b 1) '(:b 1 :a 0))
(== pl '(:b 1 :a 0)))
(util:mv-bind (a (b :not-set) c) (values 42 2)
(== a 42)
(== b 2)
(== c nil))
(let ((x 1) (b 99))
(util:mv-bind (a (b :not-set) c) (values 42 2)
(== a 42)
(== b 2)
(== c nil)
(setf x a))
(== b 99)
(== x 42))
(util:load-dotenv (t:test-path ".test.env"))
(== (util:getenv "SCOPES_USER") "user-from-env-file")
(== (util:getenv "SCOPES_PASSWORD") "very_secret"))

View file

@ -130,7 +130,7 @@
(deftest test-gene-0 ()
(let ((environ:*env* (setup (gene:config-g0)))
(rcvr (tc:receiver t:*test-suite*)))
(environ:send-create '(:csys :c00 #(0 0)) :cat :e10 :connect :succ :value 2)
(environ:send-create '(:c00 #(0 0)) :cat :e10 :connect :succ :value 2)
(sleep 0.01)
(environ:send-value '(:c00 #(0 0)) 2)
;(environ:send-value '(:c00 #(0 0)) 2)