Appeared in:
Influenced by:
Typing discipline:
File extensions:
Versions and implementations (Collapse all | Expand all):
Programming language

Alef is a concurrent programming language suited for system programming. It is implemented in Communicating Sequential Processes style.

Alef was designed at Bell Labs by Phil Winterbottom for Plan 9 operating system. It was included in first (1992) and second (1995) editions of Plan 9. There is also an Alef compiler for Silicon Graphics systems running IRIX.

The language provides error handling, process management and primitives synchronization; there is no garbage collector. There are two main models of process synchronization: shared variables and message passing. Besides, Alef supports object-oriented programming implemented using static inheritance and information hiding.

The syntax of the language is very similar to C (ANSI C dialect), but Alef programs differ in a lot of aspects. For example, Alef can use C preprocessor, but can’t use C header files; stack models of the languages are incompatible, so their object modules can’t be linked with each other.

An Alef program consists of one or several processes, each of which contains one or several tasks. Processes are threads of execution that are preemptively scheduled by the system and can execute in parallel on a multi-processor. Tasks are controlled by the Alef run-time and execute cooperatively: only one task of a process can be executed at any given moment. The first task of the first process of the program is created automatically at start time, and it starts at main() function. All following tasks and processes are created explicitly by the program itself and start in the given functions. All existing language implementations use shared memory model, though language specification doesn’t require this. For a program to stop, all its processes have to terminate.

The processes exchange information using channels — pipe-like structure which can transport data of one type specified in channel declaration. Send operator <-= transmits the result of the expression (right operand) on the channel (left operand), unary receive operator <- receives a message on the channel supplied as its only operand.

Alef supports four kinds of complex data types: union (similar to union in C), aggr (similar to a combination of struct and typedef in C), adt (abstract data type) and tuple (type with nameless components; usually tuples are used to bundle several values for transporting them via channel, passing as function argument or receiving as function return).

Alef provides two main error handling mechanisms. check statement tests an assertion and terminates the process with the given error message when the assertion fails. raise statement raises an error, and rescue statement defines a block to be executed if an error was raised.

Elements of syntax:

Non-nestable comments /* ... */
Variable identifier regexp [_a-zA-Z][_a-zA-Z0-9]*
While condition do while (condition) ...
Do until condition do ... while (!condition)


Hello, World!:

Example for versions Alef (Plan 9, edition 2)

This example illustrates the usage of channels and processes. The main process creates a channel which transmits string addresses. After this it starts a child process with channel argument, feeds message address to the channel and terminates. The second process waits for the message, prints it and terminates as well.

#include	<alef.h>

receive(chan(byte*) c)
	byte *s;
	s = <-c;
	print("%s\n", s);

	chan(byte*) c;
	alloc c;
	proc receive(c);
	c <-= "Hello, World!";