CLU (programming language)

From Infogalactic: the planetary knowledge core
(Redirected from CLU programming language)
Jump to: navigation, search
CLU
Paradigm multi-paradigm: object-oriented, procedural
Designed by Barbara Liskov and her students at MIT
Developer Barbara Liskov and her students at MIT
First appeared 1974
Typing discipline strong
Website www.pmg.lcs.mit.edu/CLU.html
Major implementations
Portable CLU, Native CLU, clu2c
Influenced by
ALGOL 60, Lisp, Simula
Influenced
Ada, Argus, Lua, Ruby, Sather, Swift[1]

CLU is a pioneering programming language created at MIT by Barbara Liskov and her students between 1974 and 1975. While it did not find extensive use itself, it introduced many features that are now widely used, and is seen as a step in the development of object-oriented programming (OOP). However, it is not object-oriented itself, instead being considered "object-based", as it lacked many features of OOP.

Key contributions include abstract data types,[2] call-by-sharing, iterators, multiple return values (a form of parallel assignment), type-safe parameterized types, and type-safe variant types. It is also notable for its use of classes with constructors and methods, but without inheritance.

Clusters

The syntax of CLU was based on ALGOL, then the starting point for most new language designs. The key addition was the concept of a cluster, CLU's type extension system and the root of the language's name (CLUster).[3] Clusters correspond generally to the concept of an "class" in an OO language, and have similar syntax. For instance, here is the CLU syntax for a cluster that implements complex numbers:

    complex_number = cluster is add, subtract, multiply, ...
        rep = record [ real_part: real, imag_part: real ]
        add = proc ... end add;
        subtract = proc ... end subtract;
        multiply = proc ... end multiply;
        ...
    end complex_number;

A cluster is a module that encapsulates all of its components except for those explicitly named in the "is" clause. These correspond to the public components of a class in recent OO languages. A cluster also defines a type that can be named outside the cluster (in this case, "complex_number"), but its representation type (rep) is hidden from external clients.

Cluster names are global, and no namespace mechanism was provided to group clusters or allow them to be created "locally" inside other clusters.

CLU does not perform implicit type conversions. In a cluster, the explicit type conversions 'up' and 'down' change between the abstract type and the representation. There is a universal type 'any', and a procedure force[] to check that an object is a certain type. Objects may be mutable or immutable, the latter being "base types" such as integers, booleans, characters and strings.[3]

Other features

Another key feature of the CLU type system are iterators, which return objects from a collection one after the other.[3] Iterators offer an identical API no matter what data they are being used with. Thus the iterator for a collection of complex_numbers can be used interchangeably with that for an array of integers. A distinctive feature of CLU iterators is that they are implemented as coroutines, with each value being provided to the caller via a "yield" statement. Iterators like those in CLU are now a common feature of many modern languages, such as C#, Ruby, and Python, though recently they are often referred to as generators.

CLU also includes exception handling, based on various attempts in other languages; exceptions are raised using signal and handled with except. Unlike most other languages with exception handling, exceptions are not implicitly resignaled up the calling chain; exceptions that are neither caught nor resignaled explicitly are immediately converted into a special failure exception that typically terminates the program.

CLU is often credited as being the first language with type-safe variant types (called oneofs), preceding ML in this respect.

A final distinctive feature in CLU is parallel assignment ("multiple assignment"), where more than one variable can appear on the left hand side of an assignment operator. For instance, writing x,y = y,x would exchange values of x and y. In the same way, functions could return several values, like x,y,z = f(t). Parallel assignment (though not multiple return values) predates CLU, appearing in CPL (1963), under the name simultaneous assignment,[4] but CLU popularized it and is often credited as the direct influence leading to parallel assignment in later languages.

All objects in a CLU program live in the heap, and memory management is automatic.

CLU supported type parameterized user-defined data abstractions. It was the first language to offer type-safe bounded parameterized types, using structure "where clauses" to express constraints on actual type arguments.

Influence on other programming languages

  • Python and Ruby borrowed several concepts from CLU, such as call by sharing, the yield statement, and multiple assignment[citation needed]
  • CLU and Ada were major inspirations for C++ templates.
  • CLU's exception handling mechanisms also influenced newer languages like C++ and Java.
  • C++, C#, Python, and Sather include iterators, which first appeared in CLU.
  • Perl and Lua took multiple assignment and multiple returns from function calls from CLU.[5]

Lua error in package.lua at line 80: module 'strict' not found.

References

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. 3.0 3.1 3.2 Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. Lua error in package.lua at line 80: module 'strict' not found.

External links