Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (57 sloc) 2.091 kb
4000e60 Some changes to the readme file
Naveen Sundar G authored
1 This is a simple and easy to use Actor system in Common Lisp.
37429a0 Added the README file.
Naveen Sundar G authored
2
3 ****** Set-Up ************
4 1. Requires Bordeaux threads. http://common-lisp.net/project/bordeaux-threads/ 2. Just load actors.lisp and start using it.
5
6 ****** Usage ************
7 An small manual can be found at :
8 http://www.cs.rpi.edu/~govinn/actors.pdf
9
10 1. Creating an actor class or template
11 (defactor Actor-Class
12 (state)
13 (message-vars)
14 behavior)
15
16 2. Creating an actor instance
17 (setq my-actor (Actor-Class (:state-var_1 value_1 ...
18 :state-var_n value_n)))
19
20 3. Sending a message
e18c83b Added examples to the README file.
Naveen Sundar G authored
21 (send my-actor message_args)
22
23 ****** Features ************
24
25 1. Concurrency using the actors model.
26 2. Dynamic behavior change of actors.
27
28 ****** Examples ************
29
30 1. A ticker: Keeps printing out a count every 2 seconds, starting from 0 and incrementing it every 2 seconds.
31
32 ;create the ticker template
33 (defactor ticker ((counter 0)) (m)
34 (sleep 2) (pr counter)
35 (incf counter) (send self nil) next)
36 ; Create an instance
37 (setf t1 (ticker))
38 ; send a message (async)
39 (send t1 nil)
40 ; to stop use
41 (stop-actor t1)
42
43 2. A print actor: Prints the message which was sent to it. A very useful utility actor.
44
45 ;create the actor template
46 (defactor print-actor () (val) (pr val) next)
47 ; initialize a new instance
48 (setf printer (print-actor))
49 ;send values for printing
50 (send printer "hello, world")
51
52 3. A factorial computing actor : The name says it all :)
53
54 ;create the template
55 (defactor fact ((temp 1)) (n cust)
56 (if (equal 1 n)
57 (progn (send cust (* temp 1))
58 (setf temp 1) next)
59 (progn (setf temp (* n temp))
60 (send self (- n 1) cust) next)))
61 ;create a new instance
62 (setf f (fact))
63 ; send a value
64 (send f 4 print-actor)
65
66 4. A nagger for fun : Works only in Mac OS X. Keeps saying out aloud "please work" every 10 seconds :)
67
68 (defactor nagger () ()
69 (sleep 10)
70 (trivial-shell:shell-command "say please work")
71 (send self) next)
72 ; anonymous actor , no way to stop the nagging
73 (send (nagger))
Something went wrong with that request. Please try again.