CPL


Compiler and Programming Language FAQ

Does your programming language use brackets like in Mathematics?

Brackets, or braces, are a syntactic construct in many programming languages. They are typically assigned different semantic meanings. In the C language parentheses or round brackets () are used to group arithmetic expressions or function arguments, square brackets [] are used for array subscripting, and braces or curly brackets {} delimit compound statements or definitions.

CPL uses brackets just as you were taught in school. All three kinds of round, square, and curly brackets are interchangeably available for grouping arithmetic expressions or any other of the above usages, but each must be matched by its own kind. To alternate parentheses, brackets and braces, though optional, is beneficial to the human eye's reading and proofreading nested formulas and enhances automatic error catching.

The provided code editor can automatically alternate bracket styles and match bracket pairs for you.

Is this an object-oriented language?

An object-oriented language (OOL) implements objects and their associated procedures within the software programming context, and encourages reuse of these objects within the same and other programs. Java, C++ and Smalltalk are popular examples of object-oriented languages. They typically bind related data and functions into a class object.

CPL supports the object paradigm but avoids the inclusion of function definitions inside classes in favour of overloaded, polymorphic functions that are qualified by the (oftentimes STRUCTURE) type of one or more of their arguments. It caters for subtyping and inheritance through anonymous STRUCTURE fields, and for dynamically typed objects through DYNAMIC pointers.

Where must a function prototype be declared?

Function prototypes exist in most languages and allow many programming errors to be caught at compile time. They are also essential to disambiguating overloaded functions. However, prototype checking in C and FORTRAN and many other compiled languages requires dedicated header or interface files that inconveniently duplicate the definitions contained in the program proper.

CPL checks prototype coherence by polling the USEd files in stead of headers, and issues compile-time errors accordingly. The prototype-enforcing process is totally transparent to the user who no longer needs to write separate header files (but may if one wants to).

Do you offer symbolic manipulation?

Symbolic manipulation software has the ability to manipulate symbolic expressions, for instance to calculate derivatives of functions containing literal symbols, performing algebra as one would with pen and paper. Macsyma, Maple and Mathematica are classic examples.

In CPL the symbolic.cpl library provides symbolic differentiation capabilities. Not only can CPL work backwards through a chain of expressions to calculate a symbolic derivative (discrete adjoint), but it does so transparently without the user needing to even see the intermediate code generated by automatic differentiation: any desired symbolic derivatives are worked out during compilation and inlined in the generated code.

In numerical optimization problems, once the expression of an objective function is programmed in, its derivatives with respect to either a scalar parameter or an array element become immediately available in the same code and can be denoted symbolically just as one would on paper.

What about linear algebra and graphics?

The CPL compiler's most distinctive feature is its incremental extensibility. The included libraries provide matrix operations, gnuplot graphics, and symbolic manipulation, among other extensions, all blended into the language syntax.

Additionally, any function provided by an external C or FORTRAN library can be seamlessly called in a CPL program with no performance penalty.

Is the process of including a C library straightforward?

The CPL compiler can read and make sense of a C header file. After a single C-like #include directive, global variables and functions declared in the header become transparently available as CPL global variables and functions with CPL syntax, error checking included.

Is variable array size supported?

CPL arrays allow variable (i.e., run-time specified) and independent lower and upper bounds of each index wherever they allow constant ones; the compiler statically or dynamically allocates memory space as needed and frees it on exit from the enclosing code block.

Array bounds can be queried through the LO and HI builtin functions, and are run-time checked by the rtchecks module.

A rich set of subarray selections, commuting with structure fields, is efficiently supported.

Is your programming language compiled?

CPL was conceived as a compiled language from the outset; when used for intensive computational tasks, it inherits the speed of compiled C. The basic cpl make command, used as
  cpl make <program>[.cpl] [<option>]
is all that is needed to compile and link the source file <program>.cpl into the executable file <program>, which you can then run by its name just like any other executable.

Can a CPL program be just run, like in a scripting language?

A scripting language or script language is a programming language that is usually interpreted at run time rather than compiled. In general, scripting languages are easier to learn and faster to code in than more structured and compiled languages such as C and C++.

Although CPL is compiled, the straight cpl run command makes it act just like a scripting language, directly running a plain-text CPL file by transparently compiling it when and only when it detects a modification.

If invoked from a shebang, cpl run makes CPL code executable like a script, but at compiled-code speed.

Do your programming tools include an interactive execution environment?

A software routine that accepts commands as input and causes them to be executed is a component of operating systems and many programming environments.

The interactive CPL interpreter accepts expressions, statements or commands at a console prompt. Any CPL or C or FORTRAN library can be loaded into the interpreter and have its functions invoked from the command prompt, either alone or embedded in a greater CPL command or expression. Unix-shell commands are accepted as well, just as are functions from the system C library.

Do you provide a code editor?

CPL includes a text editor for program development, equipped with word and syntax completion at the touch of the Tab key. Interactive cpl and the editor in fact comprise a single integrated development environment: its command-console and editor faces can be switched at the touch of a key. Both views display inside a terminal, with its minimalist look and feel; by so doing they allow for swift use over a remote connection, and even in a smartphone's ssh client if in a pinch one feels the need for it.

Is CPL a good alternative to FORTRAN and C for high performance computing?

CPL provides the same computational performance as FORTRAN or C (it eventually delegates low-level optimization to the system's C compiler, while all of its own constructions are carefully crafted not to interfere with such optimization), but adds a higher-level syntax and is generally more compact and intuitive to use. CPL enforces function prototypes without needing header or interface files. Both MPI and OpenMP parallelizations are catered for, as well as CPL's own parallel module. Third-party FORTRAN and C libraries (say LAPACK, for instance) are easily integrated into CPL programs.

Does this programming language have pointers?

C and FORTRAN have a diametrically opposite approach to pointers (variables that contain the memory address of other variables). Pointers sit at the very foundation of the C language, with the intended purpose to maximize efficiency through a close correspondence to machine language, but with the drawback of a somewhat unwieldy notation sprinkled all over with ∗'s and &'s. Pointer declarations decide whether a function argument is passed by value or by reference. Arithmetics is allowed on pointers, with greatest flexibility but also vulnerability to programming errors. The original FORTRAN 77 on the other hand banned pointers entirely, passing function arguments by reference only and forcing the programmer to replace pointers with array indices even when this sounded unnatural, as in linked lists for example; subsequent versions of FORTRAN introduced pointers of a restricted nature, with no pointer arithmetics, but widely available FORTRAN libraries still rarely use pointers.

CPL treads a middle ground by making C-like use of pointers possible, but concealing the near totality of referencing and dereferencing operations under implicit type conversion. Pointer declarations decide whether a function argument is passed by value or by reference, but no special notation has to be used in function calls. Pointer arithmetics is allowed but restricted to the allocated memory space of a single compound variable, and confined to stay there when run-time error checking is on.

Is CPL a good alternative to C++ for writing reusable code?

Code reusability may generally denote a careful programming style with meaningful identifiers and recognizable constructions, something which is to advise in any language; in the context of object-oriented programming, it specifically denotes the reuse of properties of a base class in the derived classes. CPL's classes only contain data and not functions, and are therefore ordinary STRUCTUREs. The key to their reusability is in that derived STRUCTUREs, containing the data fields of a base type plus their own, can be implicitly converted to their base type. All CPL functions are polymorphic and coactivated by the type of their arguments, and therefore functions declared with the base type as argument can automatically be reused on the derived type without modification (or just their name can be reused to declare a more specific function, as one sees fit). Since functions do not belong to a single class, reusability can be applied to more than one argument, possibly at the same time. When only the first argument is involved, a C++-like dot notation is available to be used where it sounds more adapt to the application.

Is yours a good language for embedded programming and robotics?

The CPL tools (compiler, interpreter and editor) comprise an extremely compact package (1.5 Mbytes uncompressed) and can natively run on any embedded system large enough to already host a barebones unix system and native C compiler. In addition, of course, to being available offline as a cross-compiler. The ability to #include and transparently use a C library makes existing, provided with the hardware, robotic interfaces easily accessible in this compact high-level language.

Is CPL a good alternative to MATLAB for learning numerical algorithms in college and graduate school?

Although not interoperable with MATLAB, CPL provides a similar level of ease of use and fast learning curve. CPL encourages compiled code and explicitly declared variables (but not constants). CPL is free.

What's the meaning of CPL?

  • Concealed Pointer Lookup
  • Coactive Parameter Lists
  • Consistent Procedure Linkage
  • Compiler and Programming Language
  • Conceived by Paolo Luchini