decons/csys.lisp

35 lines
895 B
Common Lisp

;;;; decons/csys - cybernetic communication systems
(defpackage :decons/csys
(:use :common-lisp)
(:local-nicknames (:actor :scopes/core/actor)
(:util :scopes/util))
(:export #:neuron #:synapse
#:forward
#:set-content
#:inhibit))
(in-package :decons/csys)
(defun neuron (proc &key state syns env)
(actor:create
(lambda (msg) (funcall proc msg state syns env))))
(defun synapse (rcvr &optional (op #'identity))
(lambda (msg)
(actor:send rcvr (funcall op msg))))
;;;; simple default / example neuron processors
(defun forward (msg state syns env)
(dolist (s syns)
(funcall s msg)))
;;;; publish/subscribe - pubsub service
;;;; helpers for operations on complex messages (with content and customer slots)
(defun set-content (fn)
(lambda (msg) (actor:set-content msg fn)))
(defun inhibit () (set-content #'-))