;;;; decons/asys - asynchronous actor systems (defpackage :decons/asys (:use :common-lisp) (:local-nicknames (:actor :scopes/core/actor) (:util :scopes/util)) (:export #:neuron #:synapse #:forward #:cumulate #:set-content #:inhibit)) (in-package :decons/asys) (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) (format t "*** forward ~a ~a~%" msg state) (dolist (s syns) (funcall s msg))) (defun cumulate (msg state syns env) (setf state (+ state msg)) (if (/= 0 state) (forward state state syns env)) (actor:become (lambda (msg) (cumulate msg state syns env)))) ;;;; 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 #'-))