minor clean-ups, improvements, functions for future use

This commit is contained in:
Helmut Merz 2026-08-05 08:38:09 +02:00
parent 83f1bab7a8
commit a0e0774a77
3 changed files with 27 additions and 9 deletions

View file

@ -11,9 +11,8 @@
(:export #:scope #:environ (:export #:scope #:environ
#:make-program #:create-zero #:make-program #:create-zero
#:neuron #:std-proc #:eff-proc #:neuron #:std-proc #:eff-proc
#:handle-action #:forward #:notify #:handle-action #:basic-actions #:forward #:notify
#:basic-actions #:merge-actions #:no-op #:printer #:value-add #:create #:connect
#:no-op #:value-add #:create #:connect
#:multiply #:multiply
#:send-create #:send-connect)) #:send-create #:send-connect))
@ -203,6 +202,9 @@
(message:create (list domain :connect) (message:create (list domain :connect)
:data (list :target target :op op)))) :data (list :target target :op op))))
(defun printer ()
(actor:create (lambda (msg) (print msg))))
;;;; internal helpers ;;;; internal helpers
(defun new-msg-head (msg scope) (defun new-msg-head (msg scope)

View file

@ -8,7 +8,7 @@
(:message :scopes/core/message) (:message :scopes/core/message)
(:shape :scopes/shape) (:shape :scopes/shape)
(:util :scopes/util)) (:util :scopes/util))
(:export #:create (:export #:create #:simple-proc
#:actions #:actions
#:send-value #:send-connect)) #:send-value #:send-connect))
@ -17,10 +17,18 @@
(defclass scope (csys:scope) (defclass scope (csys:scope)
((cells :reader cells :initform (make-hash-table :test #'equal)))) ((cells :reader cells :initform (make-hash-table :test #'equal))))
(defun create (proc meta-env) (defun create (proc &optional (meta-env (csys:printer)))
;; + create contact cells (<- &key contact-cells)
(let ((prg (csys:make-program proc))) (let ((prg (csys:make-program proc)))
(csys:neuron (csys:scope prg meta-env :cls 'scope :categ '(:env :c00))))) (csys:neuron (csys:scope prg meta-env :cls 'scope :categ '(:env :c00)))))
(defun simple-proc (msg scope)
(util:mv-bind (nmsg (scope scope))
(csys:handle-action msg scope :actions (actions))
(util:lgi msg nmsg)
(when nmsg
(actor:send (env scope) nmsg))))
;;;; action handlers ;;;; action handlers
(defun actions () (defun actions ()
@ -37,6 +45,8 @@
(new (getf data :new))) (new (getf data :new)))
(when addr (when addr
(register-cell (cells scope) addr new)) (register-cell (cells scope) addr new))
;; check: if corresponding env (contact) cell present? e.g. (:env :e00 "1-0")
;; => connect
;(csys:send-message new (list (message:domain msg) :next) :data data) ;(csys:send-message new (list (message:domain msg) :next) :data data)
(actor:send new (actor:send new
(message:create (list (message:domain msg) :next) :data data)) (message:create (list (message:domain msg) :next) :data data))
@ -73,11 +83,11 @@
(defun register-cell (reg addr cell) (defun register-cell (reg addr cell)
(destructuring-bind (dom cat &optional (key "")) addr (destructuring-bind (dom cat &optional (key "")) addr
(let* ((dcat (list dom cat)) (let* ((categ (list dom cat))
(idx (gethash dcat reg))) (idx (gethash categ reg)))
(unless idx (unless idx
(setf idx (index:create)) (setf idx (index:create))
(setf (gethash dcat reg) idx)) (setf (gethash categ reg) idx))
(index:put idx key cell)))) (index:put idx key cell))))
(defun find-cells (reg addr) (defun find-cells (reg addr)
@ -88,3 +98,9 @@
(util:lgw "not found" addr reg idx)) (util:lgw "not found" addr reg idx))
cells))) cells)))
(defun find-cell (reg addr)
(let ((cells (find-cells reg addr)))
(when (> (length cells) 1)
(util:lgw "more than one cell found" addr reg cells))
(car cells)))

View file

@ -41,7 +41,7 @@
(let ((self actor:*self*)) (let ((self actor:*self*))
(csys:send-create self :cat :e00 :loc "1-0" :connect :succ) (csys:send-create self :cat :e00 :loc "1-0" :connect :succ)
(csys:send-create self :cat :e00 :loc "1-1" :connect :succ :op (csys:multiply -1)) (csys:send-create self :cat :e00 :loc "1-1" :connect :succ :op (csys:multiply -1))
(csys:send-create self :cat :s00 :stage :basic :loc "0-1") (csys:send-create self :cat :s00 :loc "0-1" :stage :basic)
;; switch :active ;; switch :active
nil))) nil)))