util:plist-merge, use in csys:notify-created

This commit is contained in:
Helmut Merz 2026-07-13 09:10:21 +02:00
parent a20170368b
commit e816a13d41
3 changed files with 24 additions and 20 deletions

View file

@ -9,8 +9,7 @@
(:util :scopes/util) (:util :scopes/util)
(:alx :alexandria)) (:alx :alexandria))
(:export #:scope #:environ (:export #:scope #:environ
#:send #:send-message #:neuron #:synapse #:std-proc #:update #:create
#:neuron #:synapse #:std-proc #:update
#:handle-action)) #:handle-action))
(in-package :scopes/csys) (in-package :scopes/csys)
@ -59,6 +58,7 @@
(update nscope))) (update nscope)))
(defun create (msg scope) (defun create (msg scope)
;todo: use message data for modifying new scope
(let ((new (neuron (reset scope)))) (let ((new (neuron (reset scope))))
(notify-created msg new scope))) (notify-created msg new scope)))
@ -79,8 +79,8 @@
(funcall act msg scope))) (funcall act msg scope)))
(defun notify-created (msg new scope) (defun notify-created (msg new scope)
(let* ((head (list (car (shape:head msg)) :created)) (let* ((head (list (message:domain msg) :created))
(data (list :new new :old actor:*self*)) ; todo: update existing data (data (util:plist-merge (shape:data scope) '(:new new :parent actor:*self*)))
(msg1 (message:create head :data data))) (msg1 (message:create head :data data)))
(notify msg1 scope)) (notify msg1 scope))
) )

View file

@ -34,7 +34,7 @@
(config:add-action '(:csys) (constantly nil)) (config:add-action '(:csys) (constantly nil))
) )
(defun env-proc (msg scope) (defun proc-env (msg scope)
(let ((t:*test-suite* (csys:environ scope))) (let ((t:*test-suite* (csys:environ scope)))
(destructuring-bind (nmsg scope) (csys:handle-action msg scope) (destructuring-bind (nmsg scope) (csys:handle-action msg scope)
(util:lgi nmsg) (util:lgi nmsg)
@ -45,35 +45,35 @@
(load (t:test-path "config-csys" "etc")) (load (t:test-path "config-csys" "etc"))
(async:init) (async:init)
(unwind-protect (unwind-protect
(test-basic-1) (test-basic-0)
(sleep 0.1) (sleep 0.1)
(t:show-result)))) (t:show-result))))
;;;; test: initialization ;;;; test: initialization
(defun setup-test-basic-1 () (defun setup-test-basic-0 ()
(setup-config) (setup-config)
(core:setup-services) (core:setup-services)
(setf (tc:receiver t:*test-suite*) (core:find-service :test-receiver)) (setf (tc:receiver t:*test-suite*) (core:find-service :test-receiver))
;(csys:add-action '(:csys :sensor) #'csys:create-sensor) ;(csys:add-action '(:csys :sensor) #'csys:create-sensor)
(let ((env (csys:neuron (csys:scope #'env-proc (let ((env (csys:neuron (csys:scope #'proc-env
:environ (tc:receiver t:*test-suite*)))) :environ (tc:receiver t:*test-suite*)))))
;(csys:add-sensor '(:csys :init :zero) zero) ;(csys:create) ; or: (environ:setup program:basic-0 #'proc-env)
))) ))
(deftest test-basic-1 () (deftest test-basic-0 ()
(setup-test-basic-1) (setup-test-basic-0)
(sleep 0.1) (sleep 0.1)
(core:shutdown) (core:shutdown)
) )
(deftest x-test-init () (deftest x-test-init ()
(csys:send-message '(:csys :sensor :init :zero) '(:std :s1)) ;(csys:send-message '(:csys :sensor :init :zero) '(:std :s1))
(csys:send-message '(:csys :sensor :init :zero) '(:std :s2)) ;(csys:send-message '(:csys :sensor :init :zero) '(:std :s2))
(sleep 0.1) (sleep 0.1)
(csys:send-message '(:csys :add :std :s1) 1) ;(csys:send-message '(:csys :add :std :s1) 1)
(csys:send-message '(:csys :add :std :s1) 3) ;(csys:send-message '(:csys :add :std :s1) 3)
(csys:send-message '(:csys :sub :std :s2) 4) ;(csys:send-message '(:csys :sub :std :s2) 4)
(csys:send-message '(:csys :add :std :s2) 5) ;(csys:send-message '(:csys :add :std :s2) 5)
(core:shutdown) (core:shutdown)
) )

View file

@ -10,7 +10,7 @@
#:ptr #:ptr
#:rfill #:rtrim #:rfill #:rtrim
#:loop-plist #:filter-plist #:map-plist #:loop-plist #:filter-plist #:map-plist
#:plist-pairs #:plist-equal #:plist-add #:plist-pairs #:plist-equal #:plist-add #:plist-merge
#:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string #:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string
#:from-bytes #:to-bytes #:b64-decode #:b64-encode #:from-b64 #:to-b64 #:from-bytes #:to-bytes #:b64-decode #:b64-encode #:from-b64 #:to-b64
#:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string #:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string
@ -82,6 +82,10 @@
(defun plist-pairs (pl) (defun plist-pairs (pl)
(loop-plist pl k v collect (list k v))) (loop-plist pl k v collect (list k v)))
(defun plist-merge (pl1 pl2)
(loop-plist pl2 k v do (setf (getf pl1 k nil) v))
pl1)
(defun plist-equal (l1 l2) (defun plist-equal (l1 l2)
(unless (= (length l1) (length l2)) (unless (= (length l1) (length l2))
(return-from plist-equal nil)) (return-from plist-equal nil))