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;17 years ago (2003)
Stable release
2.7.4 / November 17, 2011;8 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

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 object-oriented programming, the iterator pattern is a design pattern in which an iterator is used to traverse a container and access the container's elements. The iterator pattern decouples algorithms from containers; in some cases, algorithms are necessarily container-specific and thus cannot be decoupled.

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.

For loop control flow statement

In computer science, a for-loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly. Various keywords are used to specify this statement: descendants of ALGOL use "for", while descendants of Fortran use "do". There are other possibilities, for example COBOL which uses "PERFORM VARYING".

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.

Foreach loop control flow statement

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.

In most computer programming languages, a do while loop is a control flow statement that executes a block of code at least once, and then either repeatedly executes the block, or stops executing it, depending on a given boolean condition at the end of the block.

In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is not yet complete.

XL is the first and so far the only computer programming language designed to support concept programming.

Scala (programming language) General-purpose programming language

Scala is a general-purpose programming language providing support for both object-oriented programming and functional programming. The language has a strong static type system. Designed to be concise, many of Scala's design decisions are aimed to address criticisms of Java.

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.

In computer programming, an anonymous function is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions, or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfil the same role for the function type as literals do for other data types.

Urbi is an open-source cross-platform software platform 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.

A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation character. In many high level programming languages the purpose of a label is to act as the destination of a GOTO statement. In assembly language labels can be used anywhere an address can. Also in Pascal and its derived variations. Some languages, such as Fortran and BASIC, support numeric labels. Labels are also used to identify an entry point into a compiled sequence of statements.

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.

SuperPascal is an imperative, concurrent computing programming language developed by Per Brinch Hansen. It was designed as a publication language: a thinking tool to enable the clear and concise expression of concepts in parallel programming. This is in contrast with implementation languages which are often complicated with machine details and historical conventions. It was created to address the need at the time for a parallel publication language. Arguably, few languages today are expressive and concise enough to be used as thinking tools.

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

Nim (programming language) programming language

Nim is an imperative, general-purpose, multi-paradigm, statically typed, systems, compiled programming language designed and developed by Andreas Rumpf. It 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 and C++, and compiling to C, C++, Objective-C, and JavaScript.

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