diff --git a/csys/csys.lisp b/csys/csys.lisp index 149d194..17ddb62 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -21,12 +21,10 @@ (defclass scope () ((value :accessor value :initarg :value :initform 0) - ;(params :accessor params :initarg :params :initform nil) ; <- program (categ :accessor categ :initarg :categ :initform '(:csys :c00)) (stage :accessor stage :initarg :stage :initform :initial) (proc :accessor proc) (program :reader program :initarg :program) - ;(actions :accessor actions :initarg :actions :initform nil) ; <- program (syns :accessor syns :initform nil) (environ :reader environ :initarg :environ))) @@ -75,12 +73,18 @@ (defun process (scope) (lambda (msg) (funcall (proc scope) msg scope))) -(defun std-proc (msg scope) +(defun std-proc (msg scope &key (default #'remember) params actions) (destructuring-bind (nmsg nscope) - (handle-action msg scope :default #'remember) ; + params, actions + (handle-action msg scope :default default :actions actions :params params) (forward nmsg (syns nscope)) (update nscope))) +(defun eff-proc (msg scope &key params actions) + (destructuring-bind (nmsg nscope) + (handle-action msg scope :default #'no-op :actions actions :params params) + (notify nmsg nscope) + (update nscope))) + (defun create (msg scope) (let ((new (neuron (apply #'reset-scope scope (shape:data msg))))) (notify-created msg new scope))) @@ -97,7 +101,6 @@ (defun handle-action (msg scope &key (default #'no-op) actions params) (let* ((key (message:action msg)) - ;(act (gethash key (actions scope) default)) (act (getf actions key (getf actions :default default)))) (apply act msg scope params))) @@ -105,8 +108,7 @@ (let* ((head (list (message:domain msg) :created)) (data (util:plist-merge (shape:data msg) `(:new ,new :parent ,actor:*self*))) (msg1 (message:create head :data data))) - (notify msg1 scope)) - ) + (notify msg1 scope))) ;;;; predefined neuron actions @@ -115,5 +117,4 @@ (defun remember (msg scope) (setf (value scope) (shape:data-value msg :value)) - ;(list msg (make-neuron-state (shape:data msg) syns)) (list msg scope)) diff --git a/test/test-core.lisp b/test/test-core.lisp index de7a6af..df73109 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -99,6 +99,10 @@ (let ((pl '(:a 0))) (== (util:plist-add pl :b 1) '(:b 1 :a 0)) (== pl '(:b 1 :a 0))) + (util:mv-bind (a &optional (b :not-set) (c :not-set)) (values 42 2) + (== a 42) + (== b 2) + (== c :not-set)) (util:load-dotenv (t:test-path ".test.env")) (== (util:getenv "SCOPES_USER") "user-from-env-file") (== (util:getenv "SCOPES_PASSWORD") "very_secret")) diff --git a/test/test-csys.lisp b/test/test-csys.lisp index de01794..244fecf 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -52,18 +52,18 @@ ;;;; test: initialization -(defun setup-test-basic-0 () +(defun setup-test (prg) (setup-config) (core:setup-services) (let* ((recv (core:find-service :test-receiver)) (env (environ:create #'proc-env t:*test-suite*))) (setf (tc:receiver t:*test-suite*) recv) ;(csys:create-zero (test-program) env) - (csys:create-zero (csys:make-program #'csys:std-proc) env) + (csys:create-zero prg env) env)) (deftest test-basic-0 () - (let ((env (setup-test-basic-0))) + (let ((env (setup-test (csys:make-program #'csys:std-proc)))) (sleep 0.1) (actor:send env (message:create '(:csys :value :c00 "0-0") :data '(:value 1))) (sleep 0.1) diff --git a/util/util.lisp b/util/util.lisp index 13c8e2a..80add3d 100644 --- a/util/util.lisp +++ b/util/util.lisp @@ -11,6 +11,7 @@ #:rfill #:rtrim #:loop-plist #:filter-plist #:map-plist #:plist-pairs #:plist-equal #:plist-add #:plist-merge + #:mv-bind #:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string #:from-bytes #:to-bytes #:b64-decode #:b64-encode #:from-b64 #:to-b64 #:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string @@ -97,6 +98,9 @@ (defmacro plist-add (pl k v) `(setf ,pl (cons ,k (cons ,v ,pl)))) +(defmacro mv-bind (vars vform &body body) + `(destructuring-bind ,vars (multiple-value-list ,vform) ,@body)) + ;;;; strings, symbols, keywords, ... (defun flatten-str (s &key (sep " "))