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 in matched pairs for grouping arithmetic expressions or lists of parameters, with no distinction between function arguments and array subscripts. Parentheses, brackets and braces can thus be alternated, at the user's discretion, which 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.

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 within the allocated memory space of a declared compound variable, and enforced to stay there when run-time error checking is on.

Is symbolic manipulation included?

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

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.

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 this a good language for GPU computing?

CPL transparently supports OpenMP and OpenACC directives (or in fact any other directives that fit in a #pragma), with automatic handling of array size and dimensions. GPU computing is then as easily available as in FORTRAN or C, with the added advantage of CPL's high-level syntax. GPU-precompiled libraries, or separately compiled user GPU programs, can also be easily accessed through their C interface.

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.

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

Is this an object-oriented language, or does it provide polymorphic functions?

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.

Polymorphism, on the over hand, causes a function to behave differently based on the type of its arguments, not necessarily only of the object that calls/invokes it.

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.

Is this programming language compiled?

CPL was conceived as a compiled language from the very 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 hashbang, cpl run makes CPL code executable like a script, but at compiled-code speed.

Do the 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 the programming tools include a code editor?

CPL includes a text editor for program development, equipped with word and syntax completion at the touch of the Tab key, lossless undo and a multiple insertion buffer. Interactive cpl and the editor in fact comprise a single integrated development environment (IDE): its command-console and editor faces can be swapped 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. For added flexibility the editor is UTF-8 compliant and also includes a hex editor mode.

Does the editor offer autocompletion, unlimited lossless undo and a multiple selection buffer?

The CPL editor features Tab autocompletion, parenthesis autocompletion, and CPL syntax autocompletion. Pressing Tab autocompletes the current keyword or identifier. Successive tabs move forward along the list of available words; Shift-Tab moves backwards. A hint is shown, where appropriate, of what autocompletion is available. Opened brackets are autocompleted with a closing one, and automatically alterned among the round, square and curly styles. Pressing Enter (new line) triggers the autocompletion of recognized compound CPL statements. These three actions can be individually enabled/disabled.

Unlimited undo and redo functionality is supported, of a lossless kind that goes beyond the one found in most editors. Memory of past edits is not lost even when further edits take place after an undo, and the user can choose whether to see the session's history in a traditional or extended sequence.

The CPL editor features a multiple-selection buffer: right after an insertion, pressing the insertion key again replaces the just inserted text by the historically former selection. You can recall and insert the last three items that you have recently selected, written or deleted; just try pressing Insert, and if what you see is not what you want, press Insert again.

Can we start an editor on our local machine and edit a file on a remote server?

The CPL editor internally handles remote connections specified through extended filenames prefixed with the name of the server separated by a colon, as in my.server.com:example.cpl. The connection is secured by ssh, and only an ssh server is required on the remote end.

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 higher-level constructions are carefully crafted not to interfere with such optimization), but adds a more expressive 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. GPU computing is transparently available through OpenMP and OpenACC directives.

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 be advised in any language; or, 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. They do offer reusability, however, 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 this a good programming language for embedded systems 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 for cross-compiling. 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, which includes a construct to ease the programming of state machines.

Is state machine programming made easy?

A finite state machine or automaton is a mathematical abstraction used to design algorithms. In programming, it is a set of code blocks ("states") that can be executed in an a priori unknown sequence where each block decides its immediate follower. For such needs CPL provides a straightforward CASE LOOP statement.

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