The simple-actors Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The simple-actors Reference Manual

This is the simple-actors Reference Manual, version 1, generated automatically by Declt version 2.4 patchlevel 1 "Will Decker" on Mon Jul 29 16:38:43 2019 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

simple-actors

The actor model implemented with closures.

Creating an actor

CL-USER> (defvar *result* nil)
*RESULT*
CL-USER> (defparameter *actor* (simple-actors:actor (&rest numbers)
				  (setf *result*
					(loop for n in numbers
					   collect (* n 2)))))
*ACTOR*
CL-USER> *actor*
#<SIMPLE-ACTORS:ACTOR {10069D2963}>

Actors can be sent messages that match their lambda-list. These messages go into a queue, and the actor's body is evaluated with each message in order:

CL-USER> (simple-actors:send *actor* 1 2 3 4 5 6)
NIL
CL-USER> *result*
(2 4 6 8 10 12)

Each actor has a thread associated with it:

CL-USER> (bt:all-threads)
(#<SB-THREAD:THREAD "Actor" RUNNING {1006919D53}>
 #<SB-THREAD:THREAD "finalizer" RUNNING {1001B80053}>
 #<SB-THREAD:THREAD "repl-thread" RUNNING {100250FF93}>
 #<SB-THREAD:THREAD "auto-flush-thread" RUNNING {100250FDA3}>
 #<SB-THREAD:THREAD "swank-indentation-cache-thread" RUNNING {1004458183}>
 #<SB-THREAD:THREAD "reader-thread" RUNNING {1004458083}>
 #<SB-THREAD:THREAD "control-thread" RUNNING {1004450D73}>
 #<SB-THREAD:THREAD "Swank Sentinel" RUNNING {1004164873}>
 #<SB-THREAD:THREAD "main thread" RUNNING {10005E8203}>)

The actor's thread terminates when it is sent the simple-actors:stop message. This message is not passed to the actor's body.

CL-USER> (simple-actors:send *actor* 'simple-actors:stop)
NIL
CL-USER> (bt:all-threads)
(#<SB-THREAD:THREAD "finalizer" RUNNING {1001B80053}>
 #<SB-THREAD:THREAD "repl-thread" RUNNING {100250FF93}>
 #<SB-THREAD:THREAD "auto-flush-thread" RUNNING {100250FDA3}>
 #<SB-THREAD:THREAD "swank-indentation-cache-thread" RUNNING {1004458183}>
 #<SB-THREAD:THREAD "reader-thread" RUNNING {1004458083}>
 #<SB-THREAD:THREAD "control-thread" RUNNING {1004450D73}>
 #<SB-THREAD:THREAD "Swank Sentinel" RUNNING {1004164873}>
 #<SB-THREAD:THREAD "main thread" RUNNING {10005E8203}>)

Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 simple-actors

Author

Jeremy Phelps

License

BSD

Description

Actor model implemented with closures

Version

1

Dependency

bordeaux-threads

Source

simple-actors.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 simple-actors.asd

Location

simple-actors.asd

Systems

simple-actors (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 simple-actors/actors.lisp

Dependencies
Parent

simple-actors (system)

Location

actors.lisp

Packages

simple-actors

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 simple-actors/ipc.lisp

Parent

simple-actors (system)

Location

ipc.lisp

Packages

simple-actors/ipc

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.4 simple-actors/better-handler-case.lisp

Parent

simple-actors (system)

Location

better-handler-case.lisp

Packages

simple-actors/better-handler-case

Exported Definitions

handler-case* (macro)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 simple-actors

Source

actors.lisp (file)

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 simple-actors/ipc

This package provides a basic method for threads to send messages to each other.

Source

ipc.lisp (file)

Use List
Used By List

simple-actors

Exported Definitions
Internal Definitions

Previous: , Up: Packages   [Contents][Index]

4.3 simple-actors/better-handler-case

Source

better-handler-case.lisp (file)

Nickname

handler-case*

Use List

common-lisp

Used By List

simple-actors

Exported Definitions

handler-case* (macro)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Special variables

Special Variable: *current-channel*
Package

simple-actors

Source

actors.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Macros

Macro: actor LAMBDA-LIST &rest BODY

Similar to LAMBDA, except the object created is an ACTOR instead of a FUNCTION. The ACTOR will wait
for messages and evaluate the BODY sequentially each time a message is received.

You can send messages to the actor with SEND. The &REST arguments to SEND must match the actor’s lambda-list with one exception: A message consisting of the single argument ’ACTORS:STOP will terminate the actor’s thread immediately without attempting to bind the actor’s arguments or evaluate its BODY. However, the ’ACTORS:STOP message cannot interrupt the BODY if it is being evaluated when the message is sent. ’ACTORS:STOP is processed when the actor begins waiting for a new message.

Within BODY, the variable ACTORS:SELF is lexically bound to
the current actor.

Package

simple-actors

Source

actors.lisp (file)

Macro: defactor NAME LAMBDA-LIST &body BODY

Like DEFUN but for actors. The resulting NAME is a variable whose value is an actor.

Package

simple-actors

Source

actors.lisp (file)

Macro: handler-case* FORM &rest CASES

Like HANDLER-CASE and HANDLER-BIND rolled into one. Example usage:

(handler-case* (restart-case (error "ZOMG! ERROR!")
(fuck-it () ’ignored))
(t (condition)
:before-unwind
(progn (format t "An error occurred Ignore it (y/N)? ")
(if (eq (read) ’y)
(invoke-restart ’fuck-it)))
:after-unwind
(format t "You just couldn’t fucking ignore it, could you?~%")))

:before-unwind is, of course, executed before the stack unrolls, so you can
invoke restarts from there. If no restart is invoked, the error falls through
to the :after-unwind case, where you can handle it like a regular handler-case.

If no :after-unwind form is provided and no restart is invoked, the condition is not trapped.

Package

simple-actors/better-handler-case

Source

better-handler-case.lisp (file)

Macro: server VAR &rest BODY

Spawns a thread that you can interact with through a TWO-WAY-CHANNEL.
In the new thread, that channel will be bound to the VAR (and also to ACTORS:*CURRENT-CHANNEL*) and then the BODY will be evaluated. The thread terminates when the BODY completes.

The SERVER form returns two values: The two-way-channel through which you may communicate
interactively with the server, and the thread object.

Package

simple-actors

Source

actors.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Functions

Function: channel-receive CHANNEL &key TIMEOUT ROLE ERROR-IF-EMPTY DEFAULT-VALUE NON-BLOCKING
Package

simple-actors

Source

actors.lisp (file)

Function: channel-send CHANNEL MESSAGE &key ROLE

Sends a message through a two-way-channel. The actors on either end of a two-way-channel play two roles on this channel: Either :CLIENT or :SERVER.

Package

simple-actors

Source

actors.lisp (file)

Function: get-message MAILBOX &key ERROR-IF-EMPTY DEFAULT-VALUE NON-BLOCKING TIMEOUT

Reads a message from the given MAILBOX object. By default, if there are no messages,
GET-MESSAGE will block until a message arrives in the MAILBOX.

Keys:

:NON-BLOCKING If set to T, then GET-MESSAGE will return immediately even if there are no messages. :DEFAULT-VALUE In non-blocking mode, this is the default return value if there are no messages. :ERROR-IF-EMPTY If set to T :NON-BLOCKING is also T, and there are no messages, a condition of type ’MAILBOX-IS-EMPTY will be signalled.

See also: SEND-MESSAGE, MAILBOX

Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: make-mailbox ()
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: send-message MAILBOX MESSAGE

Sends a MESSAGE to the specified MAILBOX. The MESSAGE can be any Lisp value. If the mailbox does not exist, it will be created.

See also: GET-MESSAGE

Package

simple-actors/ipc

Source

ipc.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Generic functions

Generic Function: send ACTOR &rest MESSAGE
Package

simple-actors

Source

actors.lisp (file)

Methods
Method: send (ACTOR actor) &rest MESSAGE

Previous: , Up: Exported definitions   [Contents][Index]

5.1.5 Classes

Class: actor ()
Package

simple-actors

Source

actors.lisp (file)

Direct superclasses

standard-object (class)

Direct methods

send (method)

Direct slots
Slot: mailbox
Initargs

:mailbox

Initform

(simple-actors/ipc:make-mailbox)

Slot: logic
Type

bordeaux-threads:thread

Initargs

:logic


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Special variables

Special Variable: *channel-role*
Package

simple-actors

Source

actors.lisp (file)

Special Variable: *default-channel-timeout*
Package

simple-actors

Source

actors.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Macros

Macro: without-mutex (MUTEX) &body BODY
Package

simple-actors/ipc

Source

ipc.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Functions

Function: copy-simple-process-mailbox INSTANCE
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: expand-handler-bind TYPE LAMBDA-LIST &key BEFORE-UNWIND AFTER-UNWIND

Helper for the HANDLER-CASE* macro. This one creates the HANDLER-BIND lambdas out of the :BEFORE-UNWIND form.

Package

simple-actors/better-handler-case

Source

better-handler-case.lisp (file)

Function: expand-handler-case TYPE LAMBDA-LIST &key BEFORE-UNWIND AFTER-UNWIND

Helper for the HANDLER-CASE* macro. This one creates the HANDLER-CASE handler-clauses out of the :AFTER-UNWIND form

Package

simple-actors/better-handler-case

Source

better-handler-case.lisp (file)

Function: make-simple-process-mailbox &key (LOCK LOCK) (BLOCKER BLOCKER) (UNREAD-MESSAGES UNREAD-MESSAGES) (READ-MESSAGES READ-MESSAGES)
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: mapapply FUNC LIST

Maps over a list, treating each element in the list as an argument list for FUNC.

Package

simple-actors/better-handler-case

Source

better-handler-case.lisp (file)

Function: server-interaction-repl CHANNEL &key RECEIVE-FIRST
Package

simple-actors

Source

actors.lisp (file)

Function: simple-process-mailbox-blocker INSTANCE
Function: (setf simple-process-mailbox-blocker) VALUE INSTANCE
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: simple-process-mailbox-lock INSTANCE
Function: (setf simple-process-mailbox-lock) VALUE INSTANCE
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: simple-process-mailbox-p OBJECT
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: simple-process-mailbox-read-messages INSTANCE
Function: (setf simple-process-mailbox-read-messages) VALUE INSTANCE
Package

simple-actors/ipc

Source

ipc.lisp (file)

Function: simple-process-mailbox-unread-messages INSTANCE
Function: (setf simple-process-mailbox-unread-messages) VALUE INSTANCE
Package

simple-actors/ipc

Source

ipc.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.4 Conditions

Condition: mailbox-is-empty ()
Package

simple-actors/ipc

Source

ipc.lisp (file)

Direct superclasses

condition (condition)

Condition: semaphore-timeout ()
Package

simple-actors/ipc

Source

ipc.lisp (file)

Direct superclasses

simple-error (condition)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.5 Structures

Structure: simple-process-mailbox ()
Package

simple-actors/ipc

Source

ipc.lisp (file)

Direct superclasses

structure-object (structure)

Direct slots
Slot: lock
Type

bordeaux-threads:lock

Initform

(bordeaux-threads:make-lock)

Readers

simple-process-mailbox-lock (function)

Writers

(setf simple-process-mailbox-lock) (function)

Slot: blocker
Type

bordeaux-threads:semaphore

Initform

(bordeaux-threads:make-semaphore)

Readers

simple-process-mailbox-blocker (function)

Writers

(setf simple-process-mailbox-blocker) (function)

Slot: unread-messages
Type

list

Readers

simple-process-mailbox-unread-messages (function)

Writers

(setf simple-process-mailbox-unread-messages) (function)

Slot: read-messages
Type

list

Readers

simple-process-mailbox-read-messages (function)

Writers

(setf simple-process-mailbox-read-messages) (function)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.6 Classes

Class: two-way-channel ()
Package

simple-actors

Source

actors.lisp (file)

Direct superclasses

standard-object (class)

Direct slots
Slot: inbound
Initargs

:inbound

Initform

(simple-actors/ipc:make-mailbox)

Slot: outbound
Initargs

:outbound

Initform

(simple-actors/ipc:make-mailbox)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   S  
Index Entry  Section

F
File, Lisp, simple-actors.asd: The simple-actors<dot>asd file
File, Lisp, simple-actors/actors.lisp: The simple-actors/actors<dot>lisp file
File, Lisp, simple-actors/better-handler-case.lisp: The simple-actors/better-handler-case<dot>lisp file
File, Lisp, simple-actors/ipc.lisp: The simple-actors/ipc<dot>lisp file

L
Lisp File, simple-actors.asd: The simple-actors<dot>asd file
Lisp File, simple-actors/actors.lisp: The simple-actors/actors<dot>lisp file
Lisp File, simple-actors/better-handler-case.lisp: The simple-actors/better-handler-case<dot>lisp file
Lisp File, simple-actors/ipc.lisp: The simple-actors/ipc<dot>lisp file

S
simple-actors.asd: The simple-actors<dot>asd file
simple-actors/actors.lisp: The simple-actors/actors<dot>lisp file
simple-actors/better-handler-case.lisp: The simple-actors/better-handler-case<dot>lisp file
simple-actors/ipc.lisp: The simple-actors/ipc<dot>lisp file

Jump to:   F   L   S  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
A   C   D   E   F   G   H   M   S   W  
Index Entry  Section

(
(setf simple-process-mailbox-blocker): Internal functions
(setf simple-process-mailbox-lock): Internal functions
(setf simple-process-mailbox-read-messages): Internal functions
(setf simple-process-mailbox-unread-messages): Internal functions

A
actor: Exported macros

C
channel-receive: Exported functions
channel-send: Exported functions
copy-simple-process-mailbox: Internal functions

D
defactor: Exported macros

E
expand-handler-bind: Internal functions
expand-handler-case: Internal functions

F
Function, (setf simple-process-mailbox-blocker): Internal functions
Function, (setf simple-process-mailbox-lock): Internal functions
Function, (setf simple-process-mailbox-read-messages): Internal functions
Function, (setf simple-process-mailbox-unread-messages): Internal functions
Function, channel-receive: Exported functions
Function, channel-send: Exported functions
Function, copy-simple-process-mailbox: Internal functions
Function, expand-handler-bind: Internal functions
Function, expand-handler-case: Internal functions
Function, get-message: Exported functions
Function, make-mailbox: Exported functions
Function, make-simple-process-mailbox: Internal functions
Function, mapapply: Internal functions
Function, send-message: Exported functions
Function, server-interaction-repl: Internal functions
Function, simple-process-mailbox-blocker: Internal functions
Function, simple-process-mailbox-lock: Internal functions
Function, simple-process-mailbox-p: Internal functions
Function, simple-process-mailbox-read-messages: Internal functions
Function, simple-process-mailbox-unread-messages: Internal functions

G
Generic Function, send: Exported generic functions
get-message: Exported functions

H
handler-case*: Exported macros

M
Macro, actor: Exported macros
Macro, defactor: Exported macros
Macro, handler-case*: Exported macros
Macro, server: Exported macros
Macro, without-mutex: Internal macros
make-mailbox: Exported functions
make-simple-process-mailbox: Internal functions
mapapply: Internal functions
Method, send: Exported generic functions

S
send: Exported generic functions
send: Exported generic functions
send-message: Exported functions
server: Exported macros
server-interaction-repl: Internal functions
simple-process-mailbox-blocker: Internal functions
simple-process-mailbox-lock: Internal functions
simple-process-mailbox-p: Internal functions
simple-process-mailbox-read-messages: Internal functions
simple-process-mailbox-unread-messages: Internal functions

W
without-mutex: Internal macros

Jump to:   (  
A   C   D   E   F   G   H   M   S   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
B   I   L   M   O   R   S   U  
Index Entry  Section

*
*channel-role*: Internal special variables
*current-channel*: Exported special variables
*default-channel-timeout*: Internal special variables

B
blocker: Internal structures

I
inbound: Internal classes

L
lock: Internal structures
logic: Exported classes

M
mailbox: Exported classes

O
outbound: Internal classes

R
read-messages: Internal structures

S
Slot, blocker: Internal structures
Slot, inbound: Internal classes
Slot, lock: Internal structures
Slot, logic: Exported classes
Slot, mailbox: Exported classes
Slot, outbound: Internal classes
Slot, read-messages: Internal structures
Slot, unread-messages: Internal structures
Special Variable, *channel-role*: Internal special variables
Special Variable, *current-channel*: Exported special variables
Special Variable, *default-channel-timeout*: Internal special variables

U
unread-messages: Internal structures

Jump to:   *  
B   I   L   M   O   R   S   U  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   A   C   M   P   S   T  
Index Entry  Section

A
actor: Exported classes

C
Class, actor: Exported classes
Class, two-way-channel: Internal classes
Condition, mailbox-is-empty: Internal conditions
Condition, semaphore-timeout: Internal conditions

M
mailbox-is-empty: Internal conditions

P
Package, simple-actors: The simple-actors package
Package, simple-actors/better-handler-case: The simple-actors/better-handler-case package
Package, simple-actors/ipc: The simple-actors/ipc package

S
semaphore-timeout: Internal conditions
simple-actors: The simple-actors system
simple-actors: The simple-actors package
simple-actors/better-handler-case: The simple-actors/better-handler-case package
simple-actors/ipc: The simple-actors/ipc package
simple-process-mailbox: Internal structures
Structure, simple-process-mailbox: Internal structures
System, simple-actors: The simple-actors system

T
two-way-channel: Internal classes

Jump to:   A   C   M   P   S   T