SkillAgentSearch skills...

Xl

A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites

Install / Use

/learn @c3d/Xl

README

XL - An extensible language

WARNING: XL is a work in progress. Even if there are some bits and pieces that happen to already work, XL is presently not suitable for any serious programming. Examples given below may sometimes simply not work. Take it as a painful reminder that the work is far from finished, and, who knows, as an idea for a contribution. See HISTORY for how we came to the present mess, and Compiler status for information about what is expected to work, and Compiler overview for a quick overview of the compiler internals.

XL is an extensible programming language designed to accomodate a variety of programming needs with ease. Being extensible means that the language is designed to make it very easy for programmers to adapt the language to suit their needs, for example by adding new programming constructs. In XL, extending the language is a routine operation, much like adding a function or creating a class in more traditional programming languages.

As a validation of this bold claim, XL has a single fundamental operator, the definition operator, which you write [Pattern] is [Implementation, where] [Pattern] is a program pattern, like X+Y, and [Implementation] explains how to translate that pattern, for example Add X, Y.

Everything that is built-in in most other programming languages, from basic data types to arithmetic to conditionals to loops is provided by the standard library in XL. You can replace these constructs if you want, or add your own. Adding a new kind of loop is not more difficult in XL than adding a function, and it uses the same syntax.

For more information, please consult the XL handbook, also available in asciidoc format and PDF format

WARNING This documentation, like the compiler, is work in progress and presently extremely messy, incomplete and inaccurate.

A few simple examples

A program computing the factorial of numbers between 1 and 5 would be written as follows:

0! is 1
N! is N * (N-1)!

for I in 1..5 loop
    print "The factorial of ", I, " is ", I!

As a testament to its extensible nature, fundamental operations in XL are defined in the standard library, including operations that would be implemented using keywords in more traditional languages. For example, the if statement in XL is defined by the following code:

if [[true]]  then TrueClause else FalseClause   is TrueClause
if [[false]] then TrueClause else FalseClause   is FalseClause
if [[true]]  then TrueClause                    is TrueClause
if [[false]] then TrueClause                    is false

Similarly, the while loop is defined as follows:

while Condition loop Body is
    if Condition then
        Body
        while Condition loop Body

The standard library also provides implementations for usual operations. For example, if you evaluate 1+3, this is done through a definition for + on integer values that looks like the following (where ... denotes some implementation-dependent code):

X:integer + Y:integer is ...

Dialects and use cases

Two dialects of XL further demonstrate the extensibility of the language

  • Tao3D focuses on real-time 3D animations and can be used as a scriptable presentation software, or as someone once described it, a sort of real-time 3D LaTeX Lisp. In Tao3D, you describe a slide with a program that looks like the following code:

    import Slides
    
    slide "A simple slide example",
        * "This looks like some kind of markdown language"
        * "But code makes it powerful: your mouse is on the " & position
        position is
            if mouse_x < 0 then "left" else "right"
    

    The examples above use the new syntax in XL, with is as its definition operator. Older variants of the language used -> instead. If you downloaded a pre-built binary of Tao3D, chances are that you need to replace is with -> for the code above to work as intended.

  • ELFE, formerly ELIOT (Extensible Language for the Internet of things) was an experiment on how to write distributed software that looks like a single program, for example to control swarms of devices in the context of the Internet of Things. An example of a simple ELFE program would be:

    WORKER is "worker.mycorp.com"
    MIN_TEMP is 25
    MAX_TEMP is 55
    
    invoke WORKER,
        every 2s,
            reply
                display temperature
    
    display Temp:real is
        print "The temperature of ", WORKER, " is ", Temp
    

The present branch, bigmerge, is an ongoing effort to reconverge the various dialects of XL. At the moment, it should pass most of the ELFE-level tests, although this is not actively tested. Getting it to support Tao3D is somewhat more difficult and may take some time.

If you come from another language

If you are familiar with other programming languages, here are a few things that may surprise you about XL.

  • There are no keywords. In C, if is a keyword. In XL, it's just a name.
  • The language is designed primarily to be readable and writable by humans. For example, there are special parsing rules to match how we read the code.
  • The language is homoiconic, i.e. programs are data, like in Lisp. This forms the basis of XL extensibility.
  • Evaluation is defined entirely in terms of rewrites of a very simple abstract. syntax tree that represents the program being evaluated.
  • The precedence of all operators is dynamic, in the sense that it's loaded from a configuration file
  • The language is primarily defined by its own standard library, rather than by special rules in the compiler.

Semantics: One operator to rule them all

XL has one fundamental operator, is, the definition operator. This operator can be read as transforms into, i.e. it transforms the code that is on the left into the code that is on the right.

<details> <summary>It can define simple variables</summary>
pi              is      3.1415926
</details> <details> <summary>It can define lists</summary>
words           is      "xylophage", "zygomatic", "barfitude"
</details> <details> <summary>It can define functions</summary>
abs X           is      if X < 0 then -X else X
</details> <details> <summary>It can define operators</summary>
X ≠ Y           is      not X = Y
</details> <details> <summary>It can define specializations for particular inputs</summary>
0!              is      1
N!  when N > 0  is      N * (N-1)!
</details> <details> <summary>It can define notations using arbitrary combinations of operators</summary>
A in B..C       is      A >= B and A <= C
</details> <details> <summary>It can define optimizations using specializations</summary>
X * 1           is      X
X + 0           is      X
</details> <details> <summary>It can define program structures</summary>
loop Body       is      Body; loop Body
</details> <details> <summary>It can define types</summary>
type complex    is      polar or cartesian
type cartesian  is      cartesian(re:number, im:number)
type polar      is      polar(mod:number, arg:number)

Note that types in XL indicate the shape of parse trees. In other words, the cartesian type above will match any parse tree that takes the shape of the word cartesian followed by two numbers, like for example cartesian(1,5).

</details> <details> <summary>It can define higher-order functions, i.e. functions that return functions</summary>
adder N         is      (X is N + X)
add3            is      adder 3

 // This will compute 8
 add3 5

This makes XL a truly functional language.

</details> <details> <summary>It can define maps associating a key to a value</summary>
my_map is
    0 is 4
    1 is 0
    8 is "World"
    27 is 32
    N when N < 45 is N + 1

// The following is "World"
my_map 8

// The following is 32
my_map[27]

// The following is 45
my_map (44)

This provides a functionality roughly equivalent to std::map in C++. However, it's really nothing more than a regular function with a number of special cases. The compiler can optimize some special kinds of mapping to provide an efficient implementation.

</details> <details> <summary>It can define templates (C++ terminology) or generics (Ada terminology)</summary>_
// An (inefficient) implementation of a generic 1-based array type
type array [1] of T is
    Value : T
    1 is Value
type array [N] of T when N > 1 is
    Head  : array[N-1] of T
    Tail  : T
    I when I<N is Head[I]
    I when I=N is Tail

A : array[5] of integer
for I in 1..5 loop
    A[I] := I * I
</details> <details> <summary>It can define variadic functions</summary>
min X       is X
min X, Y    is { Z is min Y; if X < Z then X else Z }

// Computes 4
min 7, 42, 20, 8, 4, 5, 30
</details>

In short, the single is operator covers all kinds of declarations that are found in other languages, using a single, easy to read

View on GitHub
GitHub Stars284
CategoryProduct
Updated3d ago
Forks15

Languages

C++

Security Score

100/100

Audited on Mar 25, 2026

No findings