This document describes the general syntax of the SARL Language.
SARL, like Java, is a statically typed language. In fact, it completely supports Java’s type system, including the primitive types like int or boolean, arrays and all the Java classes, interfaces, enumerations and annotations that reside on the class path.
Java generic types are fully supported as well: you can define type parameters on methods and classes and pass type arguments to generic types just as you are used to from Java. The type system and its conformance and casting rules are implemented as defined in the Java Language Specification.
One of the problems with Java is that you are forced to write type signatures over and over again. That is why so many people do not like static typing. But this is in fact not a problem of static typing, but simply a problem with Java. Although SARL is statically typed just like Java, you rarely have to write types down because they can be computed from the context.
In addition to Java’s auto-boxing to convert primitives to their corresponding wrapper
types (e.g. int is automatically converted to Integer when needed), there are
additional conversion rules in SARL: arrays are automatically converted to
List<ComponentType> and vice versa.
Resembling and supporting every aspect of Java’s type system ensures that there is no impedance mismatch between Java and SARL. This means that SARL and Java are 100% interoperable. There are no exceptional cases and you do not have to think in two worlds. You can invoke SARL code from Java and vice versa without any surprises or hassles.
In SARL, the names of the features (agents, variables, fields, etc.)
cannot be one of the keywords of SARL or Java.
For example, since
event is a keyword in SARL, the following is illegal:
To solve this problem (since some names come from Java, and
this language has different keywords than SARL), it
is possible to prefix the name fragment with the character
In SARL, statements are instructions that will be executed. A statement may be one of the elements described in the rest of this document.
As compared to programming languages as Java and C++, there is no need to terminate
a statement with the
Use of this statement terminator is optional, and used if you want to
put multiple statements on a line. To continue a statement on the next
line, you end the line with the
For instance, the two following lines are equivalent:
var myVariable : int = 5
var myVariable : int = 5;
In the following pages, you could find details on the different elements of the SARL syntax:
Copyright © 2014-2023 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0-SNAPSHOT.