#REDIRECT [[Christophe de Dinechin]]
{{Notability|date=March 2018}}
{{distinguish|XL (XML programming language)}}
{{Infobox programming language
| name = XL
| logo =
| caption =
| paradigm =
[[multi-paradigm programming language|Multi-paradigm]], [[concept programming|Concept-oriented]], [[imperative programming|imperative]], [[functional programming|functional]]
| year = 2000
| designer = [[Christophe de Dinechin]]
| developer = Christophe de Dinechin
| latest release version = 0.1
| latest release date = {{start date and age|mf=yes|2010|2}}
| latest test version =
| latest test date = {{start date and age|mf=yes|2010|2|27}}
| typing = [[strong typing|strong]]
| implementations =
| dialects =
| influenced by = [[Ada (programming language)|Ada]], [[C++]]
| license = [[GPLv2]]
| operating system = [[Unix-like]]
| website = {{URL|http://xlr.sf.net}}
}}
{{Portal|Free and open-source software}}
'''XL''' stands for eXtensible Language. It is the first and so far the only [[computer]] [[programming language]] designed to support concept programming.<ref>{{cite news|url=https://www.theregister.co.uk/2008/01/16/concept_programming |title=Dip into Concept Programming |first=Phil |last=Manchester |publisher=The Register |date=2008-01-16| accessdate=2010-02-03}}</ref>
{{R from merge}}
XL features programmer-reconfigurable syntax and semantics. Compiler ''plug-ins'' can be used to add new features to the language. A base set of plug-ins implements a relatively standard [[imperative programming|imperative language]]. Programmers can write their own plug-ins to implement application-specific notations, such as [[derivative|symbolic differentiation]], which can then be used as readily as built-in language features.
==Language==
XL is defined at four different levels:
* XL0 defines how an input text is transformed into a [[parse tree]].
* XL1 defines a base language with features comparable to [[C++]].
* XL2 defines the standard library, which includes common data types and operators.
* XLR defines a dynamic runtime for XL based on XL0.
XL has no [[primitive types]] nor keywords. All useful operators and data types, like integers or addition, are defined in the standard library (XL2). XL1 is [[Porting|portable]] between different execution environments. There is no such guarantee for XL2: if a particular [[central processing unit|CPU]] does not implement floating-point multiplication, the corresponding operator definition may be missing from the standard library, and using a floating-point multiply may result in a [[compile-time]] error.
The [[Hello World]] program in XL looks like the following:
use XL.TEXT_IO
WriteLn "Hello World"
An alternative form in a style more suitable for large-scale programs would be:
import IO = XL.TEXT_IO
IO.WriteLn "Hello World"
A recursive implementation of [[factorial]] in XLR looks like the following:
0! -> 1
N! -> N * (N-1)!
==Syntax==
Syntax is defined at the XL0 level. The XL0 phase of the compiler can be configured using a syntax description file, where properties like the text representation and precedence of operators are defined. A basic syntax file defines common mathematical notations, like + for addition, with the usually accepted [[order of operations]].
The parse tree consists of 7 node types, 4 [[leaf node]] types (integer, real, text and symbol) and 3 [[internal node]] types (infix, prefix and block).
* ''integer'' nodes represent an integer [[literal (computer science)|literal]], such as <code>2</code>. The <code>#</code> sign can be used to specify a base other than 10, as in (<code>2#1001</code>). A separating underscore can be used to improve readability, as in <code>1_000_000</code>.
* ''real'' nodes represent non-integral numbers, such as <code>2.5</code>. Based-notations and separators can be used, as for integer nodes, for example <code>16#F.FFF#E-10</code> is a valid real literal.
* ''text'' nodes represent textual contents. They are normally surrounded by simple or double quotes, like <code>"Hello"</code> or <code>'a'</code>, but the syntax file can be used to add other separators, including for multi-line textual contents.
* ''symbol'' nodes represent names or operators. Names are sequence of alphanumeric characters beginning with a letter, like <code>Hello</code>. XL0 preserves case, but XL1 ignores case and underscores, so that <code>JohnDoe</code> and <code>john_doe</code> are the same name. Operators are sequences of non-alphanumeric characters, like <code>*</code> or <code>=/=</code>.
* ''infix'' nodes represent two nodes related by an infix symbol, like <code>A+1</code> or <code>2 and 3</code>. Infix nodes are in particular used to separate lines, with an infix "new-line" symbol.
* ''prefix'' nodes represent two consecutive nodes, like <code>Write "Hello"</code>. It is also used for postfix notations, like <code>3!</code> or <code>Open?</code>.
* ''block'' nodes represent a node surrounded by grouping symbols, like <code>(A)</code>, <code>[Index]</code>. Indentation is internally represented by a block node.
With the default syntax file, the following is valid XL0, irrespective of any semantics.
A = B + "Hello"
It parses as:
infix("=",
symbol("A"),
infix("+",
symbol("B"), text("Hello")))
==Semantics of XL1 ==
The XL1 phase is defined as a sequence of operations on the XL0 parse tree. These operations are provided by various compiler plug-ins, that are triggered based on the shape of the parse tree.
Special constructs, <code>translate</code> and <code>translation</code>, are provided by a plug-in designed to facilitate the writing of other plug-ins. The <code>quote</code> construct generates a parse tree. Here is how these notations can be used to implement a plug-in called <code>ZeroRemoval</code> that eliminates superfluous additions and multiplications by zero.
translation ZeroRemoval
when
'X' + 0
then
return X
when
'X' * 0
then
return parse_tree(0)
A plug-in can be invoked on a whole file from the command line, or more locally in the source code using the ''pragma'' notation, as follows:
X := {Differentiate} d(sin(omega * T) * exp(-T/T0)) / dT
The XL1 phase contains a large set of plug-ins, notably <code>XLSemantics</code>, that provide common abstractions like [[subroutine]], [[data type]] and [[variable (programming)|variable]] [[declaration (computer science)|declaration]] and [[definition]], as well as basic [[structured programming]] statements, like conditionals or loops.
===Type system===
XL1 type checking is [[data type|static]], with [[generic programming]] abilities that are beyond those of languages like Ada or C++. Types like arrays or pointers, which are primitive in languages like C++, are declared in the library in XL. For instance, a one-dimensional array type could be defined as follows:
generic [Item : type; Size : integer] type array
A ''validated generic type'' is a generic type where a condition indicates how the type can be used. Such types need not have generic parameters. For instance, one can declare that a type is <code>ordered</code> if it has a less-than operator as follows:
// A type is ordered if it has a less-than relationship
generic type ordered if
A, B : ordered
Test : boolean := A < B
It is then possible to declare a function that is implicitly generic because the type <code>ordered</code> itself is generic.
// Generic function for the minimum of one item
function Min(X : ordered) return ordered is
... compute Y of type ordered ...
return Y
This also applies to generic types that have parameters, such as <code>array</code>. A function computing the sum of the elements in any array can be written as follows:
<source lang="ada">
function Sum(A : array) return array.Item is
for I in 0..array.Size-1 loop
result += A[I]
</source>
===Type-safe variable argument lists===
Functions can be [[Polymorphism (computer science)|overloaded]]. A function can be declared to use a variable number of arguments by using <code>...</code> in the parameter list (historically, the keyword <code>other</code> was used for that purpose). In such a function, <code>...</code> can be used to pass the variable number of arguments to another subroutine, a feature now called [[Variadic templates]]:
<source lang="pascal">
// Generic function for the minimum of N item
function Min(X : ordered; ...) return ordered is
result := Min(...)
if X < result then
result := X
</source>
When such a function is called, the compiler recursively instantiates functions to match the parameter list:
// Examples of use of the Min just declared
X : real := Min(1.3, 2.56, 7.21)
Y : integer := Min(1, 3, 6, 7, 1, 2)
===Expression reduction: operator overloading===
Operators can be defined using the <code>written</code> form of function declarations. Below is the code that would declare the addition of integers:
<source lang="ada">
function Add(X, Y: integer) return integer written X+Y
</source>
Such ''written forms'' can have more than two parameters. For instance, a matrix linear transform can be written as:
<source lang="ada">
function Linear(A, B, C : matrix) return matrix written A+B*C
</source>
A written form can use constants, and such a form is more specialized than a form without constants. For example:
<source lang="ada">
function Equal(A, B : matrix) return boolean written A=B
function IsNull(A : matrix) return boolean written A=0
function IsUnity(A : matrix) return boolean written A=1
</source>
The mechanism is used to implement all basic operators. An expression is progressively reduced to function calls using written forms. For that reason, the mechanism is referred to as ''expression reduction'' rather than operator overloading.
===Iterators===
XL iterators allow programmers to implement both [[Generator (computer science)|generators]] and [[iterators]].
'''import''' IO = XL.UI.CONSOLE
'''iterator''' IntegerIterator ('''var out''' Counter : '''integer'''; Low, High : '''integer''') '''written''' Counter '''in''' Low..High '''is'''
Counter := Low
'''while''' Counter <= High '''loop'''
'''yield'''
Counter += 1
''// Note that I needs not be declared, because declared 'var out' in the iterator''
''// An implicit declaration of I as an integer is therefore made here''
'''for''' I '''in''' 1..5 '''loop'''
IO.WriteLn "I=", I
==Development status and history==
XL is the result of a long language design work that began around 1992. The language was designed and implemented primarily by [[Christophe de Dinechin]].
Historically, the XL compiler was written in C++. It had achieved a point where most of the features described above worked correctly, but writing plug-ins was a nightmare, because C++ itself is not extensible, so implementing <code>translate</code>-like statements was impossible. The parse tree was more complicated, with dozens of node types, because it was designed for cross-language support. Moka was a Java-to-Java extensible compiler using the same infrastructure.
Abandoning the cross-language objectives and complex parse-tree structure, a [[Rewrite (programming)|complete rewrite]] of the compiler was started in 2003. The parse tree was vastly simplified down to the seven XL0 nodes types now in use. This new compiler [[Bootstrapping (compilers)|bootstrapped]] in 2004, and all new development is now written in XL. However, this new compiler still has somewhat incomplete XL1 support, although its abilities already exceed C++ in a few areas.
===Ancestry===
XL1 was inspired by a large number of other languages. In alphabetical order:
* [[Ada (programming language)|Ada]] inspired some of large-scale program support, [[exception handling]], tasking, and supportability aspects.
* [[BASIC]] the more modern variants that dispense of line numbers and support structured programming, showed how simple the syntax of a programming language could be.
* [[C (programming language)|C]] was used as the standard to expect in terms of runtime and machine-level support. XL will not require a virtual machine to run.
* [[C++]] and the [[standard template library]] demonstrated the need for good support of generic types, including implicit instantiation of generics (which Ada lacks).
* [[Fortran]]'s continued performance lead over C and C++ for numerical-intensive applications helped identify which language constructs would prevent useful optimizations.
* [[Java (programming language)|Java]] demonstrated the importance of a large, portable support library. Java containers also showed the limitations of an approach not based on generic programming. Interfacing with Java code remains an interesting challenge for XL.
* [[Lisp (programming language)|Lisp]] extensibility was considered as a key factor in its survival and relevance to this day. Lisp was the first language to normalize object-oriented features, despite having been designed years before object-oriented ideas were invented.
* [[Prolog]] demonstrated that alternative programming models are sometimes useful and highly productive. Every effort was made to ensure that a Prolog-style plug-in could be written for XL.
* [[Visual Basic]] showed how the parse tree representation can be dissociated from its visual presentation. Few people edit VB Forms textually. It is expected that XL edit-time plug-ins will one day provide similar abilities, by directly manipulating the parse tree.
==Semantics==
XLR is a dynamic language, originally intended as a back-end for the XL1 compiler, hence the name, which stands for XL runtime. It shares the basic XL0 syntax with XL1, but its behavior is much closer to a functional language, whereas XL1 is intended to look mostly like an imperative language. XLR has practically only one built-in operator, "->", which denotes a rewrite. The notation on the left of the rewrite is transformed into the notation on the right of the rewrite.
This mechanism is used to implement standard notations:
<source lang="ada">
if true then TrueBody else FalseBody -> TrueBody
if false then TrueBody else FalseBody -> FalseBody
</source>
The [[XL Programming Language]] uses a programming approach focusing on how ''concepts'', that live in the programmer's mind, translate into ''representations'' that are found in the [[machine code|code]] space.
== Pseudo-metrics ==
Concept programming uses ''pseudo-metrics'' to evaluate the quality of code. They are called pseudo-metrics because they relate the concept space and the code space, with a clear understanding that the concept space cannot be formalized strictly enough for a real metric to be defined. Concept programming pseudo-metrics include:
* ''[[Syntactic noise]]'' measures discrepancies between the concept and the syntax used to represent it. For instance, the semi-colon at the end of statements in [[C (programming language)|C]] can be considered as syntactic noise, because it has no equivalent in the concept space.
* ''[[Communication noise|Semantic noise]]'' measures discrepancies between the expected meaning or behavior of the concept and its actual meaning or behavior in the code. For instance, the fact that integer data types overflow (when mathematical integers do not) is a form of semantic noise.
* ''Bandwidth'' measures how much of the concept space a given code construct can represent. For instance, the overloaded addition operator in C has higher bandwidth than the <code>Add</code> instruction in assembly language, because the C operator can represent addition on floating-point numbers and not just integer numbers.
* ''Signal/noise ratio'' measures what fraction of the code space is used for representing actual concepts, as opposed to implementation information.
== Rule of equivalence, equivalence breakdown ==
The ''rule of equivalence'' is verified when the code behavior matches the original concept. This equivalence may break down in many cases. Integer overflow breaks the equivalence between the mathematical integer concept and the computerized approximation of the concept.
Many ways to break the equivalence have been given specific names, because they are very common:
* A ''___domain error'' is a condition where code executes outside of the ''___domain of equivalence'', which is the ___domain where the concept and the implementation match. An integer overflow is an example of ___domain error.
* A ''concept cast'' (also ''concept recast'' or ''concept recasting'') is a rewrite of a concept as a different concept because the original concept cannot be represented by the tools. In C, using pointers for output arguments because C doesn't support output arguments explicitly is an example of concept cast.
* A ''[[priority inversion]]'' is a form of syntactic or semantic noise introduced by some language-enforced general rule. It is called a priority inversion because the language takes precedence over the concept. In [[Smalltalk]], everything is an object, and that rule leads to the undesirable consequence that an expression like 2+3*5 doesn't obey the usual [[order of operations]] (Smalltalk interprets this as sending the message * to the number resulting from 2+3, which yields result 25 instead of 17).
== Methodology ==
To write code, concept programming recommends the following steps:
# Identify and define the relevant concepts in the concept space.
# Identify traditional notations for the concepts, or invent usable notations.
# Identify a combination of programming constructs that allows the concepts to be represented comfortably in code - That includes finding a code notation that matches the notation identified in the previous step as closely as possible.
# Write code that preserves, as much as possible, the expected behavior and semantics of the relevant aspects of the original concept.
Many programming tools often lack in notational abilities, thus concept programming sometimes requires the use of [[preprocessor]]s, [[Domain Specific Language|___domain-specific languages]], or [[metaprogramming]] techniques.
== Languages ==
[[XL Programming Language|XL]] is the only programming language known to date to be explicitly created for concept programming, but concept programming can be done in nearly any language, with varying degrees of success. [[Lisp (programming language)|Lisp]] and [[Forth (programming language)|Forth]] (and their derivatives) are examples of pre-existing languages which lend themselves well to concept programming.{{Citation needed|date=August 2010}}
==Similar works==
There are projects that exploit similar ideas to create code with higher level of abstraction. Among them are:
* [[Intentional Programming]]
* [[Language-oriented programming]]
* [[Literate programming]]
* [[Model-driven architecture]]
==References==
{{Reflist}}
==External links==
* {{official website|http://xlr.sf.net}}
* [http://mozart-dev.sf.net The historical development site]
* [https://www.theregister.co.uk/2008/01/16/concept_programming/ Coverage on XL and Concept programming at The Register]
* [http://xlr.sourceforge.net/Concept%20Programming%20Presentation.pdf Slides presenting XL and Concept Programming]
{{DEFAULTSORT:Xl (Programming language)}}
[[Category:Extensible syntax programming languages]]
[[Category:Programming languages]]
[[Category:2000 software]]
[[Category:Programming languages created in 2000]]
[[Category:High-level programming languages]]
|