Compare commits

..

2 commits

8 changed files with 61 additions and 23 deletions

View file

@ -95,6 +95,7 @@
(defun synapse (rcvr &optional op)
(lambda (msg)
;(if (eql (message:domain msg) :_meta) (setf op (handle-syn-meta msg rcvr op)) (...))
(let ((nmsg (if op (funcall op msg) msg)))
(when nmsg
(actor:send rcvr nmsg)))))
@ -153,17 +154,20 @@
(setf (value scope) (shape:data-value msg :value))
(values msg scope)))
(defun value-add (&key (bias 0) (threshold 1))
(defun value-add (&key (bias 0) (threshold 1) limits)
(lambda (msg scope)
(let* ((val (getf (shape:data msg) :value))
(newval (+ val (value scope))))
(util:lgi newval (length (syns scope)))
(newval (+ val (value scope)))
(limit2 (cadr limits)))
;(util:lgi newval (length (syns scope)))
(when limit2 (setf newval (min newval limit2)))
(if (>= newval threshold)
(let* ((head (new-msg-head msg scope))
(msg (message:create head :data (list :value newval))))
(setf (value scope) bias)
(values msg scope))
(progn
(let ((limit1 (car limits)))
(when limit1 (setf newval (max newval limit1)))
(setf (value scope) newval)
(values nil scope))))))
@ -179,9 +183,9 @@
(defun connect ()
(lambda (msg scope)
(let ((data (shape:data msg)))
(setf (syns scope)
(cons (synapse (getf data :target) (getf data :op)) (syns scope)))
(let* ((data (shape:data msg))
(syn (synapse (getf data :target) (getf data :op))))
(push syn (syns scope))
(values nil scope))))
(defun switch (&key (default :active))
@ -189,9 +193,21 @@
(let ((data (shape:data msg)))
(setf (stage scope) (getf data :stage default))
(set-proc scope)
(util:lgi (stage scope) (proc scope) (syns scope))
;(util:lgi (stage scope) (proc scope) (syns scope))
(values nil scope))))
(defun retire (msg scope)
#+// (environ:unregister *self*)
#+// (environ:remove-pred-syns *self*)
(setf (stage scope) :retired)
(setf (syns scope) nil)
(setf (proc scope)
(lambda (msg scope)
(util:lgw "message for retired cell" msg scope)
;(notify ...)
nil))
(values nil scope))
;;;; synapse ops
(defun multiply (n)

View file

@ -85,7 +85,7 @@
(defun forward (msg scope)
(let ((addr (message:addr msg)))
(if addr
(dolist (cell (find-cells (cells scope) (message:addr msg)))
(let ((cell (find-cell (cells scope) (message:addr msg))))
(actor:send cell msg))
(let ((rcvr (getf (shape:data msg) :to)))
(if rcvr

View file

@ -14,10 +14,11 @@
;;;; basic-0: minimal recursive system
(defun prog-b0 ()
(csys:make-program
(list '(:c00 :initial) (csys:std-proc :next (b0-next-zero))
'(:e00 :initial) (csys:eff-proc)
':default (csys:std-proc))))
(let ((val-action (csys:value-add :limits '(0))))
(csys:make-program
(list '(:c00 :initial) (csys:std-proc :value val-action :next (b0-next-zero))
'(:e00 :initial) (csys:eff-proc)
':default (csys:std-proc)))))
(defun b0-next-zero ()
(lambda (msg scope)
@ -35,11 +36,12 @@
:eff-contacts '(:e01 ("1-0" "1-1"))))
(defun prog-b1 ()
(csys:make-program
(list '(:s01 :initial) (csys:std-proc :next (b1-next-zero))
'(:s01 :basic) (csys:std-proc :next (b1-next-one))
'(:e01 :default) (csys:eff-proc :value (csys:value-add :bias 2))
':default (csys:std-proc))))
(let ((val-action (csys:value-add :bias 2 :limits '(0))))
(csys:make-program
(list '(:s01 :initial) (csys:std-proc :next (b1-next-zero))
'(:s01 :basic) (csys:std-proc :next (b1-next-one))
'(:e01 :default) (csys:eff-proc :value val-action)
':default (csys:std-proc)))))
(defun b1-next-zero ()
(lambda (msg scope)
@ -67,7 +69,7 @@
:eff-contacts '(:e02 ("2-0" "2-1"))))
(defun prog-b2 ()
(let ((val-action (csys:value-add :bias 2)))
(let ((val-action (csys:value-add :bias 2 :limits '(0))))
(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))

View file

@ -17,7 +17,6 @@
"core/actor" "core/message"
"forge/forge" "logging"
"util/async" "util/util"))
(:file "csys/csys" :depends-on ("core/core"))
(:file "core/message" :depends-on ("core/actor" "shape/shape"))
(:file "forge/forge" :depends-on ("util/iter" "util/util"))
(:file "logging" :depends-on ("config" "util/util"))

View file

@ -10,6 +10,8 @@
(add-package-local-nickname :basic :scopes/csys/program/basic)
(add-package-local-nickname :environ :scopes/csys/environ)
(add-package-local-nickname :message :scopes/core/message)
(add-package-local-nickname :shape :scopes/shape)
(scopes/util/async:init)
(setf environ:*env* (environ:simple-setup (basic:config-b2)))

18
space/space.lisp Normal file
View file

@ -0,0 +1,18 @@
;;;; cl-scopes/space
;;;; definitions for spatial registering and retrieving objects by location
(defpackage :scopes/space
(:use :common-lisp)
(:local-nicknames (:alx :alexandria))
(:export #:create #:put #:query))
(in-package :scopes/space)
(defclass index ()
((data :reader data :initform (make-hash-table :test #'equal))))
(defun create ()
(make-instance 'index))

View file

@ -1,4 +1,5 @@
;;;; cl-scopes/test-core - testing for the scopes-core system.
;;;; cl-scopes/test-core - testing for the scopes-core system
;;;; including shape and util packages.
(defpackage :scopes/test-core
(:use :common-lisp)

View file

@ -90,7 +90,7 @@
(deftest test-basic-2 ()
(let ((environ:*env* (setup (basic:config-b2) :delay 0.03)))
(environ:send-value '(:s02 "1-0") 1) (sleep 0.0001)
(environ:send-value '(:s02 "1-1") 2) (sleep 0.0001) ;; 2 => loop
(environ:send-value '(:s02 "1-0") 2) ;; stop loop
(environ:send-value '(:s02 "1-1") 2) (sleep 0.0001)
(environ:send-value '(:s02 "1-0") 2)
(teardown)))