From 32913677fd5d375a957b8f535298ca0f2f82824f Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 13 Apr 2025 10:13:04 +0200 Subject: [PATCH] core/actor: first primitive implementation --- core/actor.lisp | 8 +++++++- test/test-core.lisp | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/actor.lisp b/core/actor.lisp index 77c16bb..4f89af1 100644 --- a/core/actor.lisp +++ b/core/actor.lisp @@ -4,7 +4,7 @@ (:use :common-lisp) (:local-nicknames (:util :scopes/util)) (:export #:actor #:become #:create #:send - #:echo #:lgi)) + #:echo #:inc #:lgi)) (in-package :scopes/core/actor) @@ -33,3 +33,9 @@ (defun echo (ac msg) (send (customer msg) msg)) + +(defun inc (&optional (val 0)) + #'(lambda (ac msg) + (if msg ; (payload msg) + (become ac (inc (+ msg val))) + (send (create #'lgi) val)))) diff --git a/test/test-core.lisp b/test/test-core.lisp index 320887d..e4fad1f 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -128,8 +128,10 @@ (deftest test-actor () (let (a1 a2 a3) - (setf a1 (actor:create 'actor:lgi)) - (actor:send a1 "Hello World") + (setf a1 (actor:create (actor:inc))) + (actor:send a1 2) + (actor:send a1 3) + (actor:send a1 nil) )) (deftest test-send ()