Home | About | Partners | Contact Us

SourceForge Logo

Quick Links
Building XL
XL Mailing List

Understanding XL
Conceptual overview
XL examples
Inside XL
Concept Programming

In depth
Browse GIT
SourceForge Info

Other projects
GNU Project
The Mozart Project

XLR: Extensible Language and Runtime

The art of turning ideas into code

Expression reduction

Prev: XL0, XL1, XL2


Next: XL operators

Expression reduction is the method used to evaluate expressions in XL. It can be thought of as operator overloading on steroids, generalized to expressions containing more than one operator, and is best illustrated with a simple example:

// Example of expression reduction function Add (X, Y : integer) return integer written X+Y function MulAdd(X, Y, Z : integer) return integer written X+Y*Z A, B, C, D: integer D := A + B // Reduced to Add(A,B) Z := A + B * C // Reduced to MulAdd(A,B,C) Z := A * B + C // Reduced to Add(A*B,C)

A parse tree representing the expression is reduced to function calls by matching the form of the tree to forms specified by written clauses in function declarations. The type system guides the process of tree selection, so multiple written forms may exist for different types (overloading).

The same technique can be used for generic data types as well. In that case, the tree is reduced to an instantitation of generic declaration.

//Example of generic expression reduction generic [type item] type list written list of item L : list of integer // Reduced to list[integer]

In complicated cases, a single expression can be reduced through both generic reduction and function call reduction in turn. This is useful in particular to create objects of a generic type using a simple-to-use form. In that example, the notation vector K[3] of integer causes both a generic reduction (instantiating the vector[integer] type) and a run-time reduction (calling the constructor of the vector type to set its size to 3).

The detailed mechanism is described here. Note that there are few limits on XL operators.

Prev: XL0, XL1, XL2


Next: XL operators

Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)