From 57b28970c165cf61a9aed33ddda42741af082f5c Mon Sep 17 00:00:00 2001 From: Adrian Boyko Date: Tue, 25 Aug 2026 13:42:20 -0700 Subject: [PATCH 1/3] Added "delcaration" and "instantiation" sections. Added behavior call example. Made code example executable. --- code-samples/actors-behaviors.pony | 5 +++++ docs/types/actors.md | 29 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/code-samples/actors-behaviors.pony b/code-samples/actors-behaviors.pony index 0227d445..73fe0214 100644 --- a/code-samples/actors-behaviors.pony +++ b/code-samples/actors-behaviors.pony @@ -1,3 +1,8 @@ +actor Main + new create(env: Env) => + let aardvark = Aardvark("Arnie") + aardvark.eat(99) + actor Aardvark let name: String var _hunger_level: U64 = 0 diff --git a/docs/types/actors.md b/docs/types/actors.md index eac21ca5..ca6a514b 100644 --- a/docs/types/actors.md +++ b/docs/types/actors.md @@ -1,6 +1,23 @@ # Actors -An __actor__ is similar to a __class__, but with one critical difference: an actor can have __behaviours__. +In Pony, __classes__ and __actors__ share many similarities and much of what you've already learned about the former directly transfers to the latter. + +## Declaration + +Let's start by looking at how syntactically similar an actor declaration is to a class declaration. We can take one of our earlier "class Wombat" examples and turn it into an "actor Aardvark" simply by changing the `class` keyword to `actor` and renaming to "Aardvark". + +```pony +--8<-- "actors-behaviors.pony:6:12" +``` +## Instantiation + +When it comes time to instantiate an Aardvark, the syntactic similarities continue: We instantiate actors the same way we instantiate objects. Unlike other actor-oriented languages and frameworks, there's no special syntax or method to "spawn" an actor in Pony. + +```pony +--8<-- "actors-behaviors.pony:3:3" +``` + +Despite these similarities, it's important to note that there are substantial differences between actors and objects when it comes to how the rest of your Pony code will interact with them. After it's instantiated, all interaction with an actor must be through its **behaviours**. Since our Aardvark doesn't yet have any, we'll need to add some if we want it to be useful. ## Behaviours @@ -15,10 +32,16 @@ Like a function, a behaviour can have parameters. Unlike a function, it doesn't __So what does a behaviour return?__ Behaviours always return `None`, like a function without explicit result type, because they can't return something they calculate (since they haven't run yet). ```pony ---8<-- "actors-behaviors.pony" +--8<-- "actors-behaviors.pony:5" +``` + +Here we have an `Aardvark` that can eat asynchronously. Clever Aardvark. To make it eat, we simply call the "eat" behavior on that instance. + +```pony +--8<-- "actors-behaviors.pony:4:5" ``` -Here we have an `Aardvark` that can eat asynchronously. Clever Aardvark. +This looks just like a synchronous function call but we're actually **passing a message** to `aardvark` requesting that the behavior be executed asynchronously. ## Message Passing From c49644c726e40708876f2e388b5f896cb0165408 Mon Sep 17 00:00:00 2001 From: Adrian Boyko Date: Wed, 26 Aug 2026 12:37:42 -0700 Subject: [PATCH 2/3] Fixed issues reported by markdown linter. --- docs/types/actors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/types/actors.md b/docs/types/actors.md index ca6a514b..5674567c 100644 --- a/docs/types/actors.md +++ b/docs/types/actors.md @@ -4,14 +4,15 @@ In Pony, __classes__ and __actors__ share many similarities and much of what you ## Declaration -Let's start by looking at how syntactically similar an actor declaration is to a class declaration. We can take one of our earlier "class Wombat" examples and turn it into an "actor Aardvark" simply by changing the `class` keyword to `actor` and renaming to "Aardvark". +Let's start by looking at how syntactically similar an actor declaration is to a class declaration. We can take one of our earlier "class Wombat" examples and turn it into an "actor Aardvark" simply by changing the `class` keyword to `actor` and renaming to "Aardvark". ```pony --8<-- "actors-behaviors.pony:6:12" ``` + ## Instantiation -When it comes time to instantiate an Aardvark, the syntactic similarities continue: We instantiate actors the same way we instantiate objects. Unlike other actor-oriented languages and frameworks, there's no special syntax or method to "spawn" an actor in Pony. +When it comes time to instantiate an Aardvark, the syntactic similarities continue: We instantiate actors the same way we instantiate objects. Unlike some other actor-oriented languages and frameworks, there's no special syntax or method to "spawn" an actor in Pony. ```pony --8<-- "actors-behaviors.pony:3:3" From c7c6fccdfb450661dd85fdb76701b56bfa18baf7 Mon Sep 17 00:00:00 2001 From: Adrian Boyko Date: Wed, 26 Aug 2026 13:32:22 -0700 Subject: [PATCH 3/3] Trigger GitHub Actions