35 lines
793 B
Common Lisp
35 lines
793 B
Common Lisp
;;;; cl-scopes/core/actor - basic actor definitions
|
|
|
|
(defpackage :scopes/core/actor
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:util :scopes/util))
|
|
(:export #:actor #:become #:create #:send
|
|
#:echo #:lgi))
|
|
|
|
(in-package :scopes/core/actor)
|
|
|
|
;;;; basic actor and message implementation
|
|
|
|
(defclass actor ()
|
|
((behavior :accessor behavior :initarg :behavior :initform #'no-op)))
|
|
|
|
(defun become (ac bhv)
|
|
(setf (behavior ac) bhv))
|
|
|
|
(defun create (bhv &optional (cls 'actor))
|
|
(make-instance cls :behavior bhv))
|
|
|
|
(defun send (addr msg &key customer)
|
|
(let ((ac addr))
|
|
;(setf (customer msg) customer)
|
|
(funcall (behavior ac) ac msg)))
|
|
|
|
;;;; predefined behaviors
|
|
|
|
(defun no-op (ac msg))
|
|
|
|
(defun lgi (ac msg)
|
|
(util:lgi msg))
|
|
|
|
(defun echo (ac msg)
|
|
(send (customer msg) msg))
|