Fork me on GitHub

Skill Reference

This document describes how to define Skills in SARL. Before reading this document, we recommend that you read the General Syntax Reference, and the Capacity Reference.

An Action is code (a public method or function) that transforms a part of the designed system or its environment. This transformation guarantees resulting properties if the system before the transformation satisfies a set of constraints. An Action is defined in terms of pre- and post-conditions.

A Capacity is the specification of a collection of Actions. This specification makes no assumptions about the implementation of each Action. It is used to specify what an Agent can do, what behavior is required for its execution.

A Skill is a collections of Actions implementing a Capacity as described in this specification.

##1. Defining a Skill

###1.1. Basic Definition

A Skill implements a Capacity and is defined with the skill keyword. This relationship is specified with the implements keyword.

Below, a Skill is defined to output messages on the standard console (defined in the Capacity Reference). Note that all the Actions defined in the Capacity must have a definition (with a body containing code) in the Skill.

skill ConsoleLogging implements Logging {
	def info(text : String) {
	def debug(text : String) {

###1.2. Field Definition

Often it is useful or necessary to base a Skill (a Capacity’s implementation) on attributes (properties or fields).

The following example defines a Skill that uses the standard Java logging library. To avoid creating an instance of the Java logger each time the Capacity’s Actions are invoked, an instance of the Java logger is created and stored in a field of the Skill.

skill StandardJavaLogging implements Logging {
	// A field is defined in the Skill
	val logger = Logger.anonymousLogger
	def info(text : String) {
	def debug(text : String) {

###1.3. Action Definition

It is possible to declare methods in the Skill in addition to those specified by the Capacity.

skill MyLogging implements Logging {
	def info(text : String) {
	def debug(text : String) {
	// Define an utility function
	// that is outputting the text
	def output(t : String) {

###1.4. Initialization of a skill

Several elements of the skill can be used only after the skill is attached to its owning agent. For example, the value returned by the function getOwner is not null only when the skill is attached to an agent, i.e. its owner.

In order to enable the developer to write a code that is run when the skill is attached, the function install could be defined and implemented. The code below provides an example in which the value returned by getOwner is checked.

def install {
	// Initialization of the skill
	assert getOwner !== null

###1.5. Uninitialization of a skill

In a similar way as install, it is possible to execute a code when the skill is detached from it owning agent. For this purpose, the uninstall function should be defined, as illustrated below:

def uninstall {
	// Do uninstallation statements

###1.6. Constructor Definition

It is not necessary to specify a constructor for Skills unless a value will be initialized.

Two constructors are defined in the abstract Skill class:

interface Skill extends AgentTrait {

Example of constructor definition:

// The constructor is mandatory
// for defining the field "logger"
new (l : Logger) {
	super() // Call the super's constructor
	logger = l

If no constructor is defined in the skill type and a super-type is declared, implicit constructors will be assumed. Implicit constructors has the same prototypes as the constructors of the super type. Details on implicit constructors are given in the reference documentation related to the synthetic functions.

###1.7. Multiple Capacity Implementation

In some situations it is useful to combine more than one capacity in a skill. Below, the MyLogging skill is defined as an implementation of the capacities Logging and LogReader. All the Actions defined in a Capacity must have an implementation in the related Skill.

If two implemented Capacities include the same Action signature, it must be implemented only once in the Skill.

capacity LogReader {
	def open(filename : String) : int
	def info(t : String)
	def close(fid : int)
skill MyLogging implements Logging, LogReader {
	// Shared implementation for the methods
	// defind in the two Capacities.
	def info(text : String) {
	def debug(text : String) {
	def open(filename : String) : int {
		return 0
	def close(fid : int) {

###1.8. Extending a Skill

In some situations it is useful to specialize the definition of a Skill. This mechanism is supported by the inheritance feature of SARL, which has the same semantics as the inheritance mechanism of the Java object-oriented language.

The extended Skill is specified just after the extends keyword.

A Skill type can extend __only one__ other Skill type. This is similar to the constraint on the extension of classes in the Java language.

In the following code, the StandardJavaLogging Skill (defined above) is extended to override the info output.

skill ExtendedLogging extends StandardJavaLogging {
	def info(text : String) {"INFO: "+text)

###1.9. Modifiers

Modifiers are used to modify declarations of types and type members. This section introduces the modifiers for the Skill. The modifiers are usually written before the keyword for defining the Skill.

The complete description of the modifiers’ semantic is available in this section.

Skill Modifiers

A Skill may be declared with one or more modifiers, which affect its runtime behavior:


public skill Example1 implements CapacityExample {
package skill Example2 implements CapacityExample {
abstract skill Example3 implements CapacityExample {
final skill Example4 implements CapacityExample {

Field Modifiers

The modifiers for the fields in a Skill are:


public var example1 : Object
protected var example2 : Object
package var example3 : Object
private var example4 : Object

Method Modifiers

The modifiers for the methods in a Skill are:


// Public access function
public def example1 { }
// Protected access function
protected def example2 { }
// Package access function
package def example3 { }
// Private access function
private def example4 { }
// Abstract function
abstract def example5
// Not-overridable function
final def example6 { }
// Dispatch functions
dispatch def example7(p : Integer) { }
dispatch def example7(p : Float) { }

##2. Built-in Skills

Several Capacities are defined and reserved by the SARL Core Specification. The corresponding Skills are provided by the runtime environment (such as the Janus platform). The built-in Skills are described in the Built-in Capacity Reference.

##3. Use of the Skills

Details on the use of Skills may be found in the following:

##4. Legal Notice

Copyright © 2014-2019 the original authors or authors.

Licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the License. You may obtain a copy of the License.

You are free to reproduce the content of this page on copyleft websites such as Wikipedia.

Generated with the translator 0.10.0.