Actor Lang

A small language I made to give life to the pseudocode one of my teacher used to teach us actor programming.

The language is pretty small so only basic arithmetic and comparisons can be done (and obviously standard actor programming actions). It only supports integers, booleans, strings and actor references.

Licence

This software is released under the MIT licence. See the full licence text.

Language syntax

Basic types

  • Integers:10, -42, +1337

  • Strings: "Hello, world!"

  • Booleans: true, false

Maths

Basic maths are supported so you can do arithmetic or boolean logic:

1 + 1
b * b - 4 * a * c
(1 + 2) * 3
true || false
true || false && myVar
x % 2 == 0

Conditional execution

if (x == y) {
    ...
}

if (x < y) {
    ...
} else {
    ...
}

Loops

for (i in 0..10) {
    ...
}

Iterates in a range from 0 to 10 (inclusive).

You can also iterate on decreasing values:

for (i in 10..0) {
    ...
}

Iterates in a range from 10 to 0 (inclusive).

You can use «complex» expressions for the range bounds:

for (i in start..(a + b)) {
    ...
}

Printing data

display "hello";
display (1 + 2) * 3;
display true || false && true;

Prints three lines:

hello
9
true

Actor behavior definition

An actor behavior definition follows this pattern:

<actor type> (<state var1>, <state varN>) [<message item1>, <message itemN>] = <statements>

A behavior is executed when a message matching a pattern is received by an actor.

Example:

MyActor () [item1] = display item1;

MyActor (State) [item1, item2] = {
    display item1;
    display item2;
};

Tagged messages

To enable calling the right behavior of an actor with multiple behaviors of the same arity, one can tag the messages with literal values in the patterns.

Example:

MyActor () ["display-one"] = display 1;
MyActor () ["display-two"] = display 2;

These behaviors will be executed on receiving a message containing either "display-one" or "display-two".

Changing behavior

An actor can change its type (and so its behavior) based on a received message:

Empty ()  ["set", x] = become Full (x);

Full (X) ["get", sender] = {
    send [X] to sender;
    become Empty ()
};

Sending messages

send [42] to anActor;

send ["hello", 1337] to anotherActor;

Actor self reference

In a behavior, the self variable is a reference to the actor executing the code.

Creating actors instances

Instantiating an actor from a given type with a given state (e.g. MyActor (42)) is done like so:

myInstantiatedActor = create MyActor (42);

Examples

Exemples can be found in the src/dist/examples folder.

Installation

To install actorlang you must unpack a distribution from a GitHub release or one you built yourself.

GitHub release

GitHub releases are available here.

From source

  • First you need to build from source if not done yet: Building from source.

  • Then unpack a distribution outputted in <repo>/build/distributions/.

Executing code

To execute code you must run the actorlang script with an Actor Lang file as an argument.

Example:

./actorlang ./examples/counter.actor

Building from source

To build the project simply run:

./gradlew build