provide an easy way to produce an updated message in a synapse via set-content

This commit is contained in:
Helmut Merz 2025-06-05 15:30:17 +02:00
parent 2fd468e109
commit b86ea21e3c
2 changed files with 14 additions and 5 deletions

View file

@ -5,7 +5,8 @@
(:local-nicknames (:actor :scopes/core/actor) (:local-nicknames (:actor :scopes/core/actor)
(:util :scopes/util)) (:util :scopes/util))
(:export #:neuron #:synapse (:export #:neuron #:synapse
#:forward)) #:forward
#:set-content))
(in-package :decons/csys) (in-package :decons/csys)
@ -22,3 +23,10 @@
(defun forward (msg state syns env) (defun forward (msg state syns env)
(dolist (s syns) (dolist (s syns)
(funcall s msg))) (funcall s msg)))
;;;; helpers for operating on messages
(defun set-content (fn)
(lambda (msg) (actor:message
(funcall fn (actor:content msg))
(actor:customer msg))))

View file

@ -9,10 +9,11 @@
)) ))
(deftest test-neuron () (deftest test-neuron ()
(let* ((prb (csys:neuron #'probe :env t:*test-suite* :state '(42 43))) (let* ((prb (csys:neuron #'probe :env t:*test-suite* :state '(43 44)))
(fw (csys:neuron #'csys:forward :syns (list (csys:synapse prb))))) (syn (csys:synapse prb (csys:set-content (lambda (c) (+ 1 c)))))
(actor:send fw (actor:message 42)) (fw (csys:neuron #'csys:forward :syns (list syn))))
(actor:send fw (actor:message 43)) (actor:send fw 42)
(actor:send fw 43)
(sleep 0.1) (sleep 0.1)
(actor:stop prb) (actor:stop prb)
(actor:stop fw) (actor:stop fw)