Pony is an open-source, object-oriented, actor-model, capabilities-secure, high-performance programming language.
- Fast
- Type-safe
- Message-oriented (actors)
- Concurrency without data races
Pony is a good language for writing fast stream-oriented and event-oriented servers.
All concurrency is handled through actors
The Pony compiler uses reference capabilities to guarantee that a program does not have data races
- Messages that are sent to an actor are placed in a queue
- An actor processes one messages at a time
- Actors run concurrently
- When an actor is finished processing a message, it processes the next message in the queue or waits until a new message is available
- A message is handled by a
behavior
- Everything happens in the context of some behavior
- Messages can have parameters, which are aliases to objects
actor Speaker
// behavior to print out a message
be say(out: OutStream, message: String) =>
out.print(message)
actor Main
new create(env: Env) =>
let speaker = Speaker
// send `say` message to `speaker`
speaker.say(env.out, "hello")
- All aliases have a reference capability
- Reference capabilities control read and write access
- If an object can be written to then no other actor can read from it or write to it
- If more than one actor can read from an object then no actor can write to it
iso
-- alias is R/W, no other alias can R or Wtrn
-- alias is R/W, other aliases are R-onlyref
-- alias is R/W, other aliases can be R/Wval
-- alias is R-only, other aliases are R-onlybox
-- alias is R-only, other aliases can be R-only or R/Wtag
-- alias cannot R or W, other aliases can be R-only or R/W
- Create an
Env
object - Create an instance of the
Main
actor - Send that instance a
create
message withEnv
object - The
Main
actor creates new actors - Actors receive and process messages from each other or the environment
- When there are no more messages to process, terminate
- Message arguments are not copied
- Mutable data can be passed from one actor to another as long as the sender "gives up" its alias to the data
- Messages in the queue are always processed in order
- Doesn't really do type inference, does "type implication"
- No top-level functions/globals