csys/program: basic-2: simple three-layer recursive system

This commit is contained in:
Helmut Merz 2026-08-10 13:02:56 +02:00
parent 0c47aec77d
commit 8775628705
4 changed files with 51 additions and 13 deletions

View file

@ -73,11 +73,11 @@
(util:lgw "proc not found" cat stg spec)) (util:lgw "proc not found" cat stg spec))
proc)))) proc))))
(defun create-zero (prg env &key (categ '(:csys :c00)) (loc "0-0")) (defun create-zero (prg env &key (categ '(:csys :c00)) (loc "0-0") (value 0))
(let* ((domain (car categ)) (let* ((domain (car categ))
(addr (list domain (cadr categ) loc)) (addr (list domain (cadr categ) loc))
(msg (message:create (list domain :create) :data (list :addr addr))) (msg (message:create (list domain :create) :data (list :addr addr)))
(scope (scope prg env :categ categ)) (scope (scope prg env :categ categ :value value))
(zero (neuron scope))) (zero (neuron scope)))
(notify-created msg zero scope))) (notify-created msg zero scope)))

View file

@ -28,7 +28,7 @@
env)) env))
(defun simple-setup (cfg) (defun simple-setup (cfg)
(destructuring-bind (prg &key (zero-cat :c00) eff-contacts) cfg (destructuring-bind (prg &key (zero-cat :c00) (zero-val 0) eff-contacts) cfg
(let ((env (create #'simple-proc (csys:printer) :eff-contacts eff-contacts))) (let ((env (create #'simple-proc (csys:printer) :eff-contacts eff-contacts)))
(csys:create-zero prg env :categ (list csys:*domain* zero-cat)) (csys:create-zero prg env :categ (list csys:*domain* zero-cat))
env))) env)))

View file

@ -6,13 +6,13 @@
(:csys :scopes/csys) (:csys :scopes/csys)
(:environ :scopes/csys/environ) (:environ :scopes/csys/environ)
(:util :scopes/util)) (:util :scopes/util))
(:export #:basic-0 #:config-basic-1)) (:export #:prog-b0 #:config-b1 #:config-b2))
(in-package :scopes/csys/program/basic) (in-package :scopes/csys/program/basic)
;;;; basic-0: minimal recursive system ;;;; basic-0: minimal recursive system
(defun basic-0 () (defun prog-b0 ()
(csys:make-program (csys:make-program
(list '(:c00 :initial) (csys:std-proc :next (b0-next-zero)) (list '(:c00 :initial) (csys:std-proc :next (b0-next-zero))
'(:e00 :initial) (csys:eff-proc) '(:e00 :initial) (csys:eff-proc)
@ -29,11 +29,11 @@
;;;; basic-1: minimal cross-linked system ;;;; basic-1: minimal cross-linked system
(defun config-basic-1 () (defun config-b1 ()
(list (basic-1) :zero-cat :s01 (list (prog-b1) :zero-cat :s01
:eff-contacts '(:e01 ("1-0" "1-1")))) :eff-contacts '(:e01 ("1-0" "1-1"))))
(defun basic-1 () (defun prog-b1 ()
(csys:make-program (csys:make-program
(list '(:s01 :initial) (csys:std-proc :next (b1-next-zero)) (list '(:s01 :initial) (csys:std-proc :next (b1-next-zero))
'(:s01 :basic) (csys:std-proc :next (b1-next-one)) '(:s01 :basic) (csys:std-proc :next (b1-next-one))
@ -59,3 +59,42 @@
(environ:send-connect env :to self :target '(:csys :e01 "1-1")) (environ:send-connect env :to self :target '(:csys :e01 "1-1"))
;; switch :active ;; switch :active
nil))) nil)))
;;;; basic-2: three-layer recursive system
(defun config-b2 ()
(list (prog-b2) :zero-cat :c02 :zero-val 2
:eff-contacts '(:e02 ("2-0" "2-1"))))
(defun prog-b2 ()
(let ((val-action (csys:value-add :bias 2)))
(csys:make-program
(list '(:c02 :initial) (csys-std-proc :value val-action :next (b2-next-zero))
'(:c02 :basic) (csys:std-proc :value val-action :next (b2-next-one))
'(:e01 :default) (csys:eff-proc)
':default (csys:std-proc)))))
(defun b2-next-zero ()
(lambda (msg scope)
(let ((self actor:*self*)
(env (csys:environ scope)))
(csys:send-create self :cat :c02 :loc "0-1" :value 2 :stage :basic)
(csys:send-create self :cat :s02 :loc "1-0" :connect :pred)
(csys:send-create self :cat :e02 :loc "2-0" :connect :succ)
(environ:send-connect env :to self :target '(:csys :c02 "0-1")
:op (csys:multiply -1))
;; switch :active
nil)))
(defun b2-next-one ()
(lambda (msg scope)
(let ((self actor:*self*)
(env (csys:environ scope)))
(csys:send-create self :cat :s02 :loc "1-1" :connect :pred)
(csys:send-create self :cat :e02 :loc "2-1" :connect :succ)
(environ:send-connect env :to self :target '(:csys :c02 "0-0")
:op (csys:multiply -1))
;; switch :active
nil)))

View file

@ -12,7 +12,6 @@
(:environ :scopes/csys/environ) (:environ :scopes/csys/environ)
(:logging :scopes/logging) (:logging :scopes/logging)
(:message :scopes/core/message) (:message :scopes/core/message)
(:program :scopes/csys/program)
(:shape :scopes/shape) (:shape :scopes/shape)
(:util :scopes/util) (:util :scopes/util)
(:t :scopes/testing) (:t :scopes/testing)
@ -58,17 +57,17 @@
(defun setup-test (cfg) (defun setup-test (cfg)
(setup-config) (setup-config)
(core:setup-services) (core:setup-services)
(destructuring-bind (prg &key (zero-cat :c00) eff-contacts) cfg (destructuring-bind (prg &key (zero-cat :c00) (zero-val 0) eff-contacts) cfg
(let ((rcvr (core:find-service :test-receiver)) (let ((rcvr (core:find-service :test-receiver))
(env (environ:create #'proc-env t:*test-suite* :eff-contacts eff-contacts))) (env (environ:create #'proc-env t:*test-suite* :eff-contacts eff-contacts)))
(setf (tc:receiver t:*test-suite*) rcvr) (setf (tc:receiver t:*test-suite*) rcvr)
(csys:create-zero prg env :categ (list :csys zero-cat)) (csys:create-zero prg env :categ (list :csys zero-cat) :value zero-val)
env))) env)))
;;;; test definitions ;;;; test definitions
(deftest test-basic-0 () (deftest test-basic-0 ()
(let ((environ:*env* (setup-test (list (basic:basic-0))))) (let ((environ:*env* (setup-test (list (basic:prog-b0)))))
;(rcvr (tc:receiver t:*test-suite*)) ;(rcvr (tc:receiver t:*test-suite*))
(sleep 0.1) (sleep 0.1)
;(tc:expect rcvr (message:create '(:csys :effect :e01) :data '(:value 1))) ;(tc:expect rcvr (message:create '(:csys :effect :e01) :data '(:value 1)))
@ -78,7 +77,7 @@
(core:shutdown))) (core:shutdown)))
(deftest test-basic-1 () (deftest test-basic-1 ()
(let ((environ:*env* (setup-test (basic:config-basic-1)))) (let ((environ:*env* (setup-test (basic:config-b1))))
(sleep 0.1) (sleep 0.1)
(environ:send-value '(:s01 "0-0") 1) (environ:send-value '(:s01 "0-0") 1)
(environ:send-value '(:s01 "0-1") 2) (environ:send-value '(:s01 "0-1") 2)