This may be a stupid question, or at least one with some incorrect assumptions about the actors model, but perhaps someone could educate me. Suppose I set up an example actor similar to one found in the cl-actors example documentation
cl-user> (ql:quickload :cl-actors)
:CL-ACTORS
cl-user> (use-package :cl-actors)
T
cl-user> (defactor echo (stream) (message)
(format stream "~a~%" message)
next)
ECHO
cl-user> (defparameter e (echo :stream *standard-output*))
E
cl-user> (send e "Test message")
Test Message
; No value
Why is there ; No value there instead of NIL? Is there a way to get the returned value out without killing the actor thread with(bt:join-thread (cl-actors::get-thread e)) (which I suspect wouldn’t exactly do what I want in any case)? I’m specifically looking to get the return value, and not play tricks with with-output-to-string or similar.
The more general problem I’m trying to solve, in case you care, is trying to output information from an actor into a cl-who page for the client side. Something along the lines of
(with-html-output (s)
(:h1 (send e "Test message")))
which clearly won’t work if send doesn’t return anything. Pointers on the more general problem are welcome if the specific question actually proves to be stupid.
I ended up changing cl-actors slightly and adding a
send-receiveconstruct that does what I want in this situation. The modified code is here (comments encouraged). The core is this:Essentially, we declare a temporary queue, send a message with that queue as a receiver, then try to pop a value off it with an optional timeout (
0meanswait forever). This depends on the target actor accepting asenderparameter, which seems like a sufficientlyactorsy way to go about it..