Claire (programming language)

From Wikipedia, the free encyclopedia

Claire is a high-level functional and object-oriented programming language with strong rule processing capabilities. It is intended to allow the programmer to express complex algorithms in a more compact and readable manner.

Claire provides:

  • a rich type system including type intervals and second-order types (with static/dynamic typing)
  • parametric classes and methods
  • propagation rules based on events
  • dynamic versioning that supports easy exploration of search spaces
  • set-based programming with an intuitive syntax
  • simple-minded object-oriented programming
  • truly polymorphic and parametric functional programming
  • an entity-relation approach with explicit relations, inverses and unknown values

[edit] Overview

Claire was designed for sophisticated applications that involve complex data modeling, rule processing and problem solving.

Claire was meant to be used in a C++ environment, either as a satellite (linking Claire programs to C++ programs is straightforward) or as an upper layer (importing C++ programs is also easy). Claire is a general-purpose language that can be used as a complete development language, but also as a preprocessor to C++ or Java, since a Claire program can be readily translated into a C++ program (C++ is still the target language of choice, but Java is increasing in popularity).

The key set of features that distinguishes Claire from other programming languages has been dictated by experience gained in solving complex optimization problems.

Two features that distinguish Claire from procedural languages such as C++ or Java are

  • Versioning: Claire supports versioning of a user-selected view of the entire system. The view can be made as large (for expressiveness) or as small (for efficiency) as is necessary. Versions are created linearly and can be viewed as a stack of snapshots of the system. Claire supports very efficient creation/rollback of versions, which constitutes the basis for powerful backtracking, a key feature for problem solving. Unlike most logic programming languages, this type of backtracking covers any user-defined structure, not simply a set of logic variables.
  • Production rules: Claire supports rules that bind a Claire expression (the conclusion) to the combination of an event and a logical condition. Whenever this event occurs, if the condition is verified, then the conclusion is evaluated. The emphasis on events is a natural evolution from rule-based inference engines and is well suited to the description of reactive algorithms such as constraint propagation.

Claire provides automatic memory allocation/de-allocation, which would have prevented an easy implementation as a C++ library. Also, set-oriented programming is much easier with a set-oriented language like Claire than with libraries.

Claire is seven years old and the current version reaches a new level of maturity. The version 3.2 of Claire is motivated by the introduction of Java as another target language but its main feature is the handling of typed lists and sets.

Claire is a set-oriented language in the sense that sets are first-class objects, typing is based on sets and control structures for manipulating sets are parts of the core language. Similarly, lists are also first-class objects. Sets and lists may be typed. Claire can also be used as a functional programming language, with full support for lambda abstraction, where functions can be passed as parameters and returned as values, and with parametric polymorphism.

Claire is an object-oriented language with single inheritance. As in Smalltalk, everything that exists in Claire is an object. Each object belongs to a unique class and has a unique identity. Classes are the corner stones of the language, from which methods, slots and tables (relations) are defined. Although classes are restricted to a single inheritance hierarchy, they may be grouped using set union operators, and these unions may be used in most places where a multiply-inherited class would be used, which offers an alternative to multiple inheritance. In a way similar to Modula-3, Claire is a modular language that provides recursively embedded modules with associated namespaces. Module decomposition can either be parallel to the class organization (mimicking C++ encapsulation) or orthogonal (e.g., encapsulating one service among multiple classes).

Claire is a typed language, with full support for polymorphism. One can use Claire with a variety of type disciplines ranging from weakly-typed weak typing in a manner that is close to Smalltalk up to a more rigid manner close to C++. This flexibility is useful to capture programming styles ranging from prototyping to production code development. The more type information available, the more Claire's compiler will behave like a statically-typed language compiler. This is achieved with a rich type system, based on sets, that goes beyond types in C++. This type system provides functional types (second-order types) similar to those in ML, parametric types associated to parametric classes and many useful type constructors such as unions or intervals.

Claire draws its inspiration from a large number of existing languages, including Smalltalk for the object-oriented aspects, SETL for the set programming aspects, OPS5 for the production rules, Lisp for the reflection and the functional programming aspects, ML for the polymorphism and C for the general programming philosophy.

Genetically, Claire is influenced by LORE, a language developed in the mid 80s for knowledge representation, and also by LAURE, although Claire is much smaller and does not retain some of the original features of LAURE such as constraints or deductive rules (Claire is also closer to C in its spirit and its syntax than LAURE was).

[edit] Example

A function to compute the nth fibonacci number:

fib(n:integer) : integer
-> (if (n < 2) 1
else fib(n - 1) + fib(n - 2))

[edit] External links