work in progress: csys:space; + minor improvements, todo comments, ...
This commit is contained in:
parent
7f69cc051a
commit
94a444cde3
7 changed files with 44 additions and 22 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
(:shape :scopes/shape)
|
(:shape :scopes/shape)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:export #:start #:stop #:create #:send #:become #:*self*
|
(:export #:start #:stop #:create #:send #:become #:*self*
|
||||||
#:customer-message #:message #:content #:customer #:set-content
|
#:customer-message #:message #:content #:customer #:update-content
|
||||||
#:*logger* #:*root*
|
#:*logger* #:*root*
|
||||||
#:echo #:inc #:lgi
|
#:echo #:inc #:lgi
|
||||||
#:calculator #:plus #:minus #:show))
|
#:calculator #:plus #:minus #:show))
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
(:method (msg) nil))
|
(:method (msg) nil))
|
||||||
|
|
||||||
(defclass customer-message ()
|
(defclass customer-message ()
|
||||||
((customer :reader customer :initarg :customer :initform nil)))
|
((customer :accessor customer :initarg :customer :initform nil)))
|
||||||
|
|
||||||
(defclass message (customer-message)
|
(defclass message (customer-message)
|
||||||
((content :reader content :initarg :content :initform nil)))
|
((content :reader content :initarg :content :initform nil)))
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
(defun message (content &optional customer)
|
(defun message (content &optional customer)
|
||||||
(make-instance 'message :content content :customer customer))
|
(make-instance 'message :content content :customer customer))
|
||||||
|
|
||||||
(defgeneric set-content (msg fn)
|
(defgeneric update-content (msg fn)
|
||||||
(:documentation "Create a new message with content returned by calling `fn`
|
(:documentation "Create a new message with content returned by calling `fn`
|
||||||
with the content of the input `msg`.")
|
with the content of the input `msg`.")
|
||||||
(:method (msg fn) (funcall fn msg))
|
(:method (msg fn) (funcall fn msg))
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@
|
||||||
(defmethod actor:content ((msg message))
|
(defmethod actor:content ((msg message))
|
||||||
(list (shape:head-plist msg) (shape:data msg)))
|
(list (shape:head-plist msg) (shape:data msg)))
|
||||||
|
|
||||||
|
(defmethod actor:update-content ((msg message) fn)
|
||||||
|
(create (shape:head msg) :data (fn (shape:data msg)) :customer (actor:customer msg)))
|
||||||
|
|
||||||
(defun domain (msg)
|
(defun domain (msg)
|
||||||
(car (shape:head msg)))
|
(car (shape:head msg)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@
|
||||||
(funcall s msg)))
|
(funcall s msg)))
|
||||||
|
|
||||||
(defun notify (msg scope)
|
(defun notify (msg scope)
|
||||||
|
(setf (actor:customer msg) actor:*self*)
|
||||||
(actor:send (environ scope) msg))
|
(actor:send (environ scope) msg))
|
||||||
|
|
||||||
;;;; action handlers
|
;;;; action handlers
|
||||||
|
|
@ -182,6 +183,7 @@
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(defun connect ()
|
(defun connect ()
|
||||||
|
;; TODO: target may be a list => check if already connected
|
||||||
(lambda (msg scope)
|
(lambda (msg scope)
|
||||||
(let* ((data (shape:data msg))
|
(let* ((data (shape:data msg))
|
||||||
(syn (synapse (getf data :target) (getf data :op))))
|
(syn (synapse (getf data :target) (getf data :op))))
|
||||||
|
|
@ -197,8 +199,8 @@
|
||||||
(values nil scope))))
|
(values nil scope))))
|
||||||
|
|
||||||
(defun retire (msg scope)
|
(defun retire (msg scope)
|
||||||
#+// (environ:unregister *self*)
|
#+// (environ:unregister actor:*self*)
|
||||||
#+// (environ:remove-pred-syns *self*)
|
#+// (environ:remove-pred-syns actor:*self*)
|
||||||
(setf (stage scope) :retired)
|
(setf (stage scope) :retired)
|
||||||
(setf (syns scope) nil)
|
(setf (syns scope) nil)
|
||||||
(setf (proc scope)
|
(setf (proc scope)
|
||||||
|
|
@ -255,7 +257,7 @@
|
||||||
|
|
||||||
(defun notify-created (msg new scope)
|
(defun notify-created (msg new scope)
|
||||||
(let* ((head (list (message:domain msg) :created))
|
(let* ((head (list (message:domain msg) :created))
|
||||||
(data (util:plist-merge (shape:data msg) `(:new ,new :parent ,actor:*self*)))
|
(data (util:plist-merge (shape:data msg) `(:new ,new)))
|
||||||
(msg1 (message:create head :data data)))
|
(msg1 (message:create head :data data)))
|
||||||
(notify msg1 scope)))
|
(notify msg1 scope)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defun forward-connect (msg scope)
|
(defun forward-connect (msg scope)
|
||||||
|
;; TODO: target may be nil => replace with list of candidates
|
||||||
(let* ((data (shape:data msg))
|
(let* ((data (shape:data msg))
|
||||||
(tgt (getf data :target)))
|
(tgt (getf data :target)))
|
||||||
(when (listp tgt)
|
(when (listp tgt)
|
||||||
|
|
@ -113,6 +114,7 @@
|
||||||
(send-message head `(:value ,val) :env env)))
|
(send-message head `(:value ,val) :env env)))
|
||||||
|
|
||||||
(defun send-connect (rcvr target &key (domain csys:*domain*) (env *env*) op)
|
(defun send-connect (rcvr target &key (domain csys:*domain*) (env *env*) op)
|
||||||
|
;; TODO: use msg.customer instead of :to in data
|
||||||
(let* ((cat-loc (when (listp rcvr) rcvr))
|
(let* ((cat-loc (when (listp rcvr) rcvr))
|
||||||
(head (cons domain (cons :connect cat-loc)))
|
(head (cons domain (cons :connect cat-loc)))
|
||||||
(data (unless cat-loc (list :to rcvr))))
|
(data (unless cat-loc (list :to rcvr))))
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@
|
||||||
(lambda (msg scope)
|
(lambda (msg scope)
|
||||||
(let ((self actor:*self*)
|
(let ((self actor:*self*)
|
||||||
(environ:*env* (csys:environ scope)))
|
(environ:*env* (csys:environ scope)))
|
||||||
|
;(environ:send-create self :cat :s02 :connect :pred) ;find loc -> csys:...
|
||||||
(csys:send-create self :cat :s02 :loc #(1 1) :connect :pred)
|
(csys:send-create self :cat :s02 :loc #(1 1) :connect :pred)
|
||||||
(csys:send-create self :cat :e02 :loc #(2 1) :connect :succ)
|
(csys:send-create self :cat :e02 :loc #(2 1) :connect :succ)
|
||||||
(environ:send-connect self '(:c02 #(0 0)) :op op-inhibit)
|
(environ:send-connect self '(:c02 #(0 0)) :op op-inhibit)
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,35 @@
|
||||||
(defpackage :scopes/csys/space
|
(defpackage :scopes/csys/space
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:local-nicknames (:alx :alexandria)
|
(:local-nicknames (:alx :alexandria)
|
||||||
(:util :scopes/util)
|
(:util :scopes/util))
|
||||||
)
|
(:export #:create #:put #:del #:fetch #:query
|
||||||
(:export #:create #:put #:fetch #:query))
|
#:neighbors #:free-loc-at #:distance-sq))
|
||||||
|
|
||||||
(in-package :scopes/csys/space)
|
(in-package :scopes/csys/space)
|
||||||
|
|
||||||
(defun create ()
|
(defun create ()
|
||||||
(make-hash-table :test #'equalp))
|
(make-hash-table :test #'equalp))
|
||||||
|
|
||||||
(defun put (space key value)
|
(defun put (spc loc obj)
|
||||||
(let ((current (gethash key space)))
|
(let ((current (gethash loc spc)))
|
||||||
(if current
|
(if current
|
||||||
(util:lgw "location already occupied" space key current value)
|
;(util:lgw "location already occupied" spc loc current obj)
|
||||||
(setf (gethash key space) value))))
|
(error "location already occupied! space: ~s, loc: ~s, current: ~s, new: ~s"
|
||||||
|
spc loc current obj)
|
||||||
|
(setf (gethash loc spc) obj))))
|
||||||
|
|
||||||
(defun fetch (space key)
|
(defun del (spc loc)
|
||||||
(gethash key space))
|
(remhash loc spc))
|
||||||
|
|
||||||
(defun query (space pattern)
|
(defun fetch (spc loc)
|
||||||
|
(gethash loc spc))
|
||||||
|
|
||||||
|
(defun query (spc pattern)
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
(defun neighbors (spc loc &key (dist 2)))
|
||||||
|
|
||||||
|
(defun free-loc-at (spc loc &key (dist 2)))
|
||||||
|
|
||||||
|
(defun distance-sq (spc loc1 loc2))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,15 @@
|
||||||
;;;; test definitions
|
;;;; test definitions
|
||||||
|
|
||||||
(deftest test-space ()
|
(deftest test-space ()
|
||||||
(let ((idx (space:create)))
|
(let ((spc (space:create)))
|
||||||
(space:put idx #(1 1) 42)
|
(space:put spc #(1 1) 42)
|
||||||
(space:put idx #(1 2) 46)
|
(space:put spc #(1 2) 46)
|
||||||
(space:put idx #(1 1) 43)
|
(ignore-errors
|
||||||
(== (space:fetch idx #(1 1)) 42)
|
(space:put spc #(1 1) 43))
|
||||||
(== (space:fetch idx #(1 2)) 46)
|
(== (space:fetch spc #(1 1)) 42)
|
||||||
|
(== (space:fetch spc #(1 2)) 46)
|
||||||
|
(space:del spc #(1 1))
|
||||||
|
(== (space:fetch spc #(1 1)) nil)
|
||||||
))
|
))
|
||||||
|
|
||||||
(deftest test-basic-0 ()
|
(deftest test-basic-0 ()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue