Coder Social home page Coder Social logo

common-lisp-actors's Introduction

This is a simple and easy to use Actor system in Common Lisp. 

****** Set-Up ************
1. Requires Bordeaux threads. http://common-lisp.net/project/bordeaux-threads/ 2. Just load actors.lisp and start using it. 

****** Usage ************
An small manual can be found at : 
http://www.cs.rpi.edu/~govinn/actors.pdf

1. Creating an actor class or template
  (defactor Actor-Class
            (state)
	    (message-vars)
	    behavior)

2. Creating an actor instance 
   (setq my-actor (Actor-Class (:state-var_1 value_1 ...
   	 	  	        :state-var_n value_n)))

3. Sending a message
   (send my-actor message_args)

****** Features ************

1. Concurrency using the actors model.
2. Dynamic behavior change of actors.

****** Examples ************

1. A ticker: Keeps printing out a count every 2 seconds, starting from 0 and incrementing it every 2 seconds. 

;create the ticker template
(defactor ticker ((counter 0)) (m) 
	     (sleep 2) (pr counter)
	        (incf counter) (send self nil) next)
; Create an instance
(setf t1 (ticker))
; send a message (async)
(send t1 nil)
; to stop use
(stop-actor t1)

2. A print actor: Prints the message which was sent to it. A very useful utility actor. 

;create the actor template
(defactor print-actor () (val) (pr val) next)
; initialize a new instance
(setf printer (print-actor))
;send values for printing
(send printer "hello, world")

3. A factorial computing actor : The name says it all :)

;create the template
(defactor fact ((temp 1)) (n cust) 
	     (if (equal 1 n) 
	            (progn (send cust (* temp 1))
                      (setf temp 1) next)
		             (progn (setf temp (* n temp))
                      (send self (- n 1) cust) next)))
;create a new instance 
(setf f (fact))
; send a value
(send f 4 print-actor)

4. A nagger for fun : Works only in Mac OS X. Keeps saying out aloud "please work" every 10 seconds :)

 (defactor nagger () () 
    (sleep 10)
       (trivial-shell:shell-command "say please work")
          (send self) next)
; anonymous actor , no way to stop the nagging 
(send (nagger))

common-lisp-actors's People

Contributors

naryl avatar nixz avatar peterhil avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.