From 2f5a3b1d7400b6b5223dd04e7125b0d4b966faf9 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 18 Jun 2025 17:04:44 +0200 Subject: [PATCH] csys: first running neuron example with two sensors (just logging) --- csys/csys.lisp | 24 +++++++++++++++--------- test/etc/config-csys.lisp | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/csys/csys.lisp b/csys/csys.lisp index 4868c0e..33f613a 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -10,16 +10,18 @@ (:shape :scopes/shape) (:util :scopes/util) (:alx :alexandria)) - (:export #:printer #:send - #:*sensors*)) + (:export #:send #:*sensors* #:neuron + #:nprint)) (in-package :scopes/csys) (defvar *sensors* (make-hash-table :test #'equal)) (defun send (msg) - (dolist (sn (find-create-sensors msg)) - (actor:send sn msg))) + (if (eq (shape:head-value msg :domain) :csys) + (dolist (sn (find-create-sensors msg)) + (actor:send sn msg)) + (core:handle-message core:*root* msg))) (defun find-create-sensors (msg) (let* ((key (cddr (shape:head msg))) @@ -34,9 +36,13 @@ (setf (gethash key *sensors*) tsks)) (util:lgw "no action selected" msg)))))) -;;;; example behaviors / actions +;;;; neurons (= behavior generators) -(defun printer (msg) - (util:lgi msg) - ;(format t "~&~a" msg) - ) +(defun neuron (proc &optional state syns env) + (lambda (msg) (funcall proc msg state syns env))) + +;;;; predefined neuron processors + +(defun nprint (msg state syns env) + (util:lgi msg state) + (actor:become (neuron #'nprint (shape:data msg) syns env))) diff --git a/test/etc/config-csys.lisp b/test/etc/config-csys.lisp index b6669f0..70de0e1 100644 --- a/test/etc/config-csys.lisp +++ b/test/etc/config-csys.lisp @@ -4,8 +4,8 @@ (config:root) -(config:add-action '(:csys :sensor :log) #'csys:printer) -;(config:add-action '(:test) #'csys:printer) +(config:add-action '(:csys :sensor :log) + (csys:neuron #'csys:nprint :testing)) (config:add :logger :class 'logging:config :loglevel (config:from-env :loglevel :info)