Simpl (SIMulation Programming Language) is a high-level programming language for building agent-based simulations. Its syntax is similar to Python's and some of its features are inspired by NetLogo. It also features some unique features like queries and a global entity pool.
The interpreter was written in Go. It's still not feature complete, but it has enough features to write simulations.
A download for the interpreter and example programs are coming soon.
Syntax
Basic statements
Printing values to the standard output
print "Hello"
print 1 + 2
Assignment
name = "Simpl"
points = 9000
Conditionals
if points > 0 {
print true
} else {
print false
}
For loops
for i in range(0, 10) {
print i
}
While loops
while a < 10 {
print a
a = a + 1
}
Comments
# This won't be executed
Expressions
a + b # If one of the variables is a string, this will perform a concatenation
a - b
a * b
a / b
a % b
a > b
a >= b
a < b
a <= b
a == b
a != b
a and b
a or b
!a
-a
Simulation features
Entities
Entities are a fundamental data type in Simpl. They represent the "Agents" in the agent-based simulation and they have tags and properties.
EntitySet
EntitySet is a data structure that contains one or more entities. It is used in queries and other operations that use more than 1 entity. Looping through an EntitySet returns its member entities at random.
Creating entities
# Creates 10 entities tagged voter. All entities need a tag when they are created.
make 10 voter
Entity properties
yordan["favorite_fruit"] = "lemon" # Sets the favorite_fruit property of yordan
print yordan["favorite_fruit"] # Access the favorite_fruit property and print it
Checking if an entity has a tag
en is voter # Returns true if en is has the tag true, or false if not
Queries
voters = tagged voter # Returns an EntitySet with all entities tagged "voter" and assigns
it to the variable voters.
Chaining queries with ->
# el is a keyword that is used for filtering which elements are returned
# The following expression returns all entities
# 1. That are tagged voter AND
# 2. That are not tagged candidate AND
# 3. Whose age property is larger than 18
tagged voter -> !(el is candidate) -> el["age"] > 18
Tagging entities
# The following statements work on both entities and EntitySets
tag yordan developer # Add a tag to the entity Yordan
tag (tagged developer) smart # Add a tag to the EntitySet developers
# Remove a "smart" tag from an entity
untag yordan smart