Skip to content
Pippijn van Steenhoven edited this page Mar 12, 2014 · 16 revisions

Try Aldor

Curious? Give it a go at Try Aldor.

What is Aldor?

From Wikipedia:

Aldor is a programming language. It is the successor of A# as the extension language of the Axiom computer algebra system.

The Aldor language combines imperative, functional, and object-oriented features. It has an elaborate dependent type system, allowing types to be used as first-class values. Aldor's syntax is heavily influenced by Pascal, but it is optionally indentation-sensitive, like Python. In its current implementation, it is compiled, but an interactive listener is provided.

Aldor License

Why Aldor?

Easy syntax

The Aldor grammar is consistent and unambiguous. Both a compiler and a human reader can immediately know what a piece of code means. The meaning and semantic effect of syntax does not depend on the context.

Few built-ins

Without a library, Aldor is pretty much an empty language. There are no integers, strings, arrays, etc. All that is defined within a library. By importing Integer into the current scope, integer literals gain meaning. Before that, the lexical structure of integer literals is defined by the compiler, but the value is not known. Only when a library implements a function from Literal to Integer, the literal can be assigned a value. Such a thing has recently been added to C++, but it's still far from the ease of use that Aldor offers.

Everything is a value

The difference between types, functions and objects as it exists in C does not exist in Aldor. Aldor differentiates between constants and variables. Types, functions and objects are all values in Aldor. You may pass types to functions and let those functions return a new type based on that old type. For example, the List "type" is actually a function that returns a type, "List of T" where T is the type passed to the List function.

Return type overloading

In C++, Java, C# and other languages, you can overload functions by their argument types and count. In Aldor, you can additionally overload them by return type. You can also overload constants, which might be seen as nullary functions that don't need the function application operator.

-- "zero"-values for different types
z: Boolean == false;
z: Integer == 0;
z: String == "";

-- returns the argument matching the wanted return type
get (i: Integer, b: Boolean): Integer == i;
get (i: Integer, b: Boolean): Boolean == b;

-- need to explicitly state the type for disambiguation
i : Integer := get (1, true);
b : Boolean := get (1, true);
Dependent types

These are a little like C++ templates. Basically, it means that you can have a type that depends on a value. You can then use regular Aldor control structures to construct a type based on that value.

#include "aldor"
#include "aldorio"

-- import operations (Literal, quo, mod, +, ~=) on Integers
-- into the current scope
import from Integer;

define FooType(i: Integer): Category == with {
   foo: () -> Integer;

   -- provide a default implementation dividing integers by 2
   default {
      foo(): Integer == i quo 2;
   }
}

-- template<int i> class Foo;
-- actually a function returning a type
Foo(i: Integer): FooType(i) == add {
   -- override the default implementation only if i is not divisible by 2
   if i mod 2 ~= 0 then {
      foo(): Integer == i + 1;
   }
}

-- call foo() in domain Foo(3) (template class Foo<3>)
stdout << foo()$Foo(3) << newline;
stdout << foo()$Foo(4) << newline;

The output from the above code would be:

4
2

The value a type depends on may be any constant value of any type, unlike in C++, where only types, integers, templates and pointers are allowed. Since types are values in Aldor, you can also have types depending on other types, which would be the template<typename T> construct in C++.