Urbiscript

Last updated
urbiscript
Paradigm multi-paradigm: object-oriented, event-driven, imperative, functional, procedural, reflective
Designed by Jean-Christophe Baillie
Developer Gostai et al.
First appeared2003;21 years ago (2003)
Stable release
2.7.4 / November 17, 2011;13 years ago (2011-11-17)
Typing discipline duck, dynamic
OS Cross-platform
License BSD licenses [1]
Filename extensions .u
Website github.com/urbiforge/urbi
Influenced by
C++, Self, [2] Io [2]

urbiscript is a programming language for robotics. [3] 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.

Contents

Memory management is performed by reference counting.

Tightly bound to the Urbi platform it supports seamless integration of C++/Java components.

Syntax and semantics

Inspiration

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. [2]

It is designed to program, but also interact with robots; [2] 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

Sequential statements and control flow

urbiscript statements include (among others): [4]

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:

varstatus={if(closed)"closed"else"open"};varpass={try{foo}catch{false}else{true}};

Concurrent statements and control flow

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]

Statement composition

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 & 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: [5]

{{sleep(2s);echo(2)},{sleep(1s);echo(1)},};echo(3);
[00012451] *** 1
[00013447] *** 2
[00013447] *** 3

Concurrent flavors of sequential constructs

Most looping constructs in urbiscript come in several "flavors", which are based on the four statement separators: ;, |, ,, and &.

For instance

// This is actually "for;".for(vari:[0,1,2]){echo(i);echo(i**2);};

displays

[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:

for&(vari:[0,1,2]){echo(i);echo(i**2);};
[00021680] *** 0
[00021680] *** 1
[00021680] *** 2
[00021682] *** 0
[00021682] *** 1
[00021682] *** 4

Event-based programming

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".

Explicit event handling

Event handling goes into three steps. First, define an event

vare=Event.new;

Second, specify event handlers

at(e?)echo("received event e");

Third, "emit" this event

e!;
[00014333] *** received event e

Events can have payloads, and event handlers enjoy pattern matching on the payload:

at(e?(1,varx)ifx%2==0)echo("received event e(1, %s)"%x);e!(1,1);
[00014336] *** received event e
e!(1,2);
[00014336] *** received event e
[00014336] *** received event e(1, 2)

Implicit events

The urbiscript language also allows to monitor expressions:

at(batteryLevel<=0.2)robot.goToChargingDock;

The following example demonstrates the feature:

varx=0;
[00002165] 0
vary=0;
[00002166] 0
varz=0;
[00002167] 0
at(x+y==z)echo("%s + %s == %s"%[x,y,z]);
[00002168] *** 0 + 0 == 0
x=1;
[00002169] 1
z=1;
[00002170] 1
[00002170] *** 1 + 0 == 1

See also

Related Research Articles

<span class="mw-page-title-main">Lua (programming language)</span> Lightweight programming language

Lua is a lightweight, high-level, multi-paradigm programming language designed mainly for embedded use in applications. Lua is cross-platform software, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C application programming interface (API) to embed it into applications.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

In computer programming, an iterator is an object that progressively provides access to each item of a collection, in order.

In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement is a fundamental construct.

In the C programming language, Duff's device is a way of manually implementing loop unrolling by interleaving two syntactic constructs of C: the do-while loop and a switch statement. Its discovery is credited to Tom Duff in November 1983, when Duff was working for Lucasfilm and used it to speed up a real-time animation program.

<span class="mw-page-title-main">For loop</span> Control flow statement for repeated execution

In computer science, a for-loop or for loop is a control flow statement for specifying iteration. Specifically, a for-loop functions by running a section of code repeatedly until a certain condition has been satisfied.

In computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator.

<span class="mw-page-title-main">Foreach loop</span> Control flow statement for traversing items in a collection

In computer programming, foreach loop is a control flow statement for traversing items in a collection. foreach is usually used in place of a standard for loop statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages, an iterator, even if implicit, is often used as the means of traversal.

Harbour is a computer programming language, primarily used to create database/business programs. It is a modernised, open source and cross-platform version of the older Clipper system, which in turn developed from the dBase database market of the 1980s and 1990s.

Structured text, abbreviated as ST or STX, is one of the five languages supported by the IEC 61131-3 standard, designed for programmable logic controllers (PLCs). It is a high level language that is block structured and syntactically resembles Pascal, on which it is based. All of the languages share IEC61131 Common Elements. The variables and function calls are defined by the common elements so different languages within the IEC 61131-3 standard can be used in the same program.

<span class="mw-page-title-main">JavaScript syntax</span> Set of rules defining correctly structured programs

The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.

<span class="mw-page-title-main">Python syntax and semantics</span> Set of rules defining correctly structured programs

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.

B-Prolog was a high-performance implementation of the standard Prolog language with several extended features including matching clauses, action rules for event handling, finite-domain constraint solving, arrays and hash tables, declarative loops, and tabling. First released in 1994, B-Prolog is now a widely used CLP system. The constraint solver of B-Prolog was ranked top in two categories in the Second International Solvers Competition, and it also took the second place in P class in the second ASP solver competition and the second place overall in the third ASP solver competition. B-Prolog underpins the PRISM system, a logic-based probabilistic reasoning and learning system. B-Prolog is a commercial product, but it can be used for learning and non-profit research purposes free of charge. B-Prolog is not anymore actively developed, but it forms the basis for the Picat programming language.

Urbi is an open-source cross-platform software computing platform written in C++ used to develop applications for robotics and complex systems. Urbi is based on the UObject distributed C++ component architecture. It also includes the urbiscript orchestration language which is a parallel and event-driven script language. UObject components can be plugged into urbiscript and appear as native objects that can be scripted to specify their interactions and data exchanges. UObjects can be linked to the urbiscript interpreter, or executed as autonomous processes in "remote" mode.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.

List comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical set-builder notation as distinct from the use of map and filter functions.

PL/SQL is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database, TimesTen in-memory database, and IBM Db2. Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database.

<span class="mw-page-title-main">Nim (programming language)</span> Programming language

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level system programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

Jean-Christophe Baillie is a French scientist and entrepreneur. He founded the ENSTA ParisTech Robotics Lab where he worked on developmental robotics and computational evolutionary linguistics. While at ENSTA, he designed the urbiscript programming language to control robots, which became the base technology of Gostai, a robotics startup he created in 2006, which was acquired by Aldebaran Robotics in 2012.

References

  1. "Urbi, the open source operating system for robots" . Retrieved 2012-10-27.
  2. 1 2 3 4 Baillie, Jean-Christophe; Demaille, Akim; Nottale, Matthieu; Hocquet, Quentin; Tardieu, Samuel (2008). "The Urbi Universal Platform for Robotics" (PDF). Retrieved 6 October 2011.
  3. Baillie, Jean-Christophe (8 July 2008). "Urbi: a new parallel & event-driven script language for robotics, games and more". YouTube. Retrieved 6 Oct 2011.
  4. "urbiscript Language Reference Manual" . Retrieved 2011-09-20.
  5. 1 2 Baillie, Jean-Christophe; Demaille, Akim; Nottale, Matthieu; Hocquet, Quentin (2010). "Tag: Job Control in urbiscript" (PDF). Retrieved 6 October 2011.
  6. Baillie, Jean-Christophe; Demaille, Akim; Nottale, Matthieu; Hocquet, Quentin (2010). "Events! (Reactivity in urbiscript)". arXiv: 1010.5694 [cs.PL].