message, csys: functions for accessing action and object keys in message heads

This commit is contained in:
Helmut Merz 2026-04-07 08:10:47 +02:00
parent 90fad03268
commit 429634dd82
2 changed files with 12 additions and 5 deletions

View file

@ -6,7 +6,7 @@
(:shape :scopes/shape) (:shape :scopes/shape)
(:util :scopes/util)) (:util :scopes/util))
(:export #:message-meta #:message #:create (:export #:message-meta #:message #:create
#:head #:data)) #:action-key #:object-key))
(in-package :scopes/core/message) (in-package :scopes/core/message)
@ -28,3 +28,12 @@
(defmethod actor:content ((msg message)) (defmethod actor:content ((msg message))
(list (shape:head-plist msg) (shape:data msg))) (list (shape:head-plist msg) (shape:data msg)))
(defun action-key (msg)
(let ((head (shape:head msg)))
(list (car head) (cadr head))))
(defun object-key (msg)
(let ((head (shape:head msg)))
(cons (car head) (cddr head))))

View file

@ -81,8 +81,7 @@
(actor:send sn msg))) (actor:send sn msg)))
(defun find-sensors (msg) (defun find-sensors (msg)
(let* ((head (shape:head msg)) (let* ((key (message:object-key msg))
(key (cons (car head) (cddr head)))
(sns (gethash key (sensors *environment*)))) (sns (gethash key (sensors *environment*))))
;(util:lgi key sns *environment*) ;(util:lgi key sns *environment*)
sns)) sns))
@ -99,8 +98,7 @@
(funcall s msg))) (funcall s msg)))
(defun handle-action (msg state syns &key (default #'no-op)) (defun handle-action (msg state syns &key (default #'no-op))
(let* ((head (shape:head msg)) (let* ((key (message:action-key msg))
(key (list (car head) (cadr head)))
(act (gethash key (actions *environment*) default))) (act (gethash key (actions *environment*) default)))
(funcall act msg state syns))) (funcall act msg state syns)))