urbiscript | |
Paradigm: | multi-paradigm object-oriented, event-driven, imperative, functional, procedural, reflective |
Designer: | Jean-Christophe Baillie |
Developer: | Gostai et al. |
Latest Release Version: | 2.7.4 |
Typing: | duck, dynamic |
Influenced By: | C++, Self, Io |
Operating System: | Cross-platform |
License: | BSD licenses[1] |
File Ext: | .u |
urbiscript is a programming language for robotics.[2] It features syntactic support for concurrency and event-based programming. It is a prototype-based object-oriented scripting language. It is dynamic: name resolution is performed during the program execution (late binding); slots (member variables) can be added/removed at runtime, and even prototypes (superclasses) of an object can be changed at runtime.
Memory management is performed by reference counting.
Tightly bound to the Urbi platform it supports seamless integration of C++/Java components.
From the syntactical point of view, urbiscript belongs to the C-family of programming languages.
Its prototype-based object-oriented design was influenced by the Self and the Io programming languages.
It is designed to program, but also interact with robots;[3] as such, it is influenced by Unix shells and other languages that provide a read-eval-print loop style interactive toplevel. However, contrary to others, there is no prompt for user input but answers from the system are prefixed by a timestamp (in milliseconds) between square brackets: 1 + 1; sleep(1s); 1 + 2 * 3;
[00005420] 2
[00006420] 7
urbiscript statements include (among others):[4]
if
statement, which conditionally executes a block of code, along with else
.for
statement, as in C which iterates over an iterable object, capturing each element to a local variable for use by the attached block.for
statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.while
statement, which executes a block of code as long as its condition is true.try
statement, which allows exceptions thrown in its attached code block to be caught and handled by catch
clauses. An optional else
clause is run if no exception was thrown. Clean-up code can be guaranteed to be run in every case when given in a finally
-clause.assert
statement, used during debugging to check for conditions that ought to apply. urbiscript also feature assert
blocks, which can be used to factor several assert
statements.Actually, contrary to most C-like languages and despite what the syntax suggests, statements "have a value", and therefore are expressions, provided they are embedded in braces:
In urbiscript, some control-flow constructs come in several "flavors": two types of sequential composition, and two types of concurrent composition. Under the hood, concurrency is implemented using coroutines.[5]
Like in C, the semicolon denotes sequential composition: a;b
stands for "run statement a
then run statement b
. Other tasks may be run between a
and b
. Another statement separator, pipe, denotes "tight sequential composition": no other task can be run between a
and b
in a|b
.
Similarly urbiscript features two means to compose statements concurrently. With a,b
, first a
is run, and at some point b
will be --- possibly while a
is still running. This is very similar to the [[Job control (Unix)|&]]
operator in Unix shells. Alternatively, with a&b
, both a
and b
are started together; in interactive sessions, this means that a
won't be run until b
is fully entered and properly followed by either a ;
or a ,
.
Scopes are boundaries for backgrounded jobs, as demonstrated in the following example:
[00012451] *** 1
[00013447] *** 2
[00013447] *** 3
Most looping constructs in urbiscript come in several "flavors", which are based on the four statement separators: ;
, |
, ,
, and &
.
For instance
[00002919] *** 0
[00002921] *** 0
[00002921] *** 1
[00002922] *** 1
[00002922] *** 2
[00002922] *** 4
i.e., the loop bodies are not executed sequentially, while the for&
keyword runs the loop bodies concurrently:
[00021680] *** 0
[00021680] *** 1
[00021680] *** 2
[00021682] *** 0
[00021682] *** 1
[00021682] *** 4
Aiming at the development of portable robotic applications,[6] urbiscript relies on specific syntactic constructs to specify reactive behaviors such as "go to the charging dock when the battery is low", "play a friendly sound when a known face is recognized", or "stop when an obstacle is detected".
Event handling goes into three steps. First, define an event
[00014333] *** received event e
Events can have payloads, and event handlers enjoy pattern matching on the payload:
[00014336] *** received event e
[00014336] *** received event e
[00014336] *** received event e(1, 2)
The urbiscript language also allows to monitor expressions:
[00002165] 0
[00002166] 0
[00002167] 0
%s" % [x, y, z]);
[00002168] *** 0 + 0
[00002169] 1
[00002170] 1
[00002170] *** 1 + 0