History and Special Features
The Alef programming language was designed by Phil Winterbottom of Bell Labs as part of the Plan 9 operating system.
It is a concurrent, object oriented-supporting programming language designed for system software based on C.
Alef is currently abandoned and not widely used for a decade. Direct Accessor of Alef is said to be the "Limbo" language.
"Hello World" Program
#include <alef.h>
void main(void) {
print("Hello World\n");
terminate(nil);
}
Fundamental Data Types and Assignment Operators
A small set of types is defined by the language. More complex types may be derived from the basic types.
Name | Size | Type |
---|---|---|
byte | 8 bits | unsigned byte |
sint | 16 bits | signed short integer |
usint | 16 bits | unsigned short integer |
int | 32 bits | signed integer |
uint | 32 bits | unsigned integer |
float | 64 bits | floating point |
lint | 64 bits | long signed integer |
ulint | 64 bits | unsigned long integer |
chan | 32 bits | channel |
poly | 64 bits | polymorphic |
The assignment operator is "=". It assigns the value of a variable or expression on the right side to the variable on the left.
Assignment examples:
int a = 2; //Assigns the value 2 to the variable of type integer 'a'
float b = 2.2; //Assigns the value 2.2 to the variable of type float 'b'
byte* str = "Hello" //Alef style of string assignment
byte c = 'v' // Alef stlye of char assignment
Variables can be assigned also from a multiple return statement of a function
:
(int, byte* ,byte) func() {
return(2,"Hello",'c');
}
void main(void) {
int a;
byte* str;
byte c;
(a,str,c)=func();//a will be 2,str-Hello,c-c
terminate(nil);
}
Basic Control Flow
Conditional Operators:
if(expression) { statement } else //optional to use {statement }
switch expression cbody
typeof expression cbody
int a=3;
if(a==3) {
print("a is 3");
}else {
print("a is not 3");
}
byte b='V';
switch b {
case 'V' :
print ("b has value V");
break;
case 'C' :
print ("b has value C");
break;
default :
print ("Unknown Value");
}
int a=3;
typeof a {
case int :
print ("a is of type int");
break;
case float :
print ("a is of type float");
break;
default :
print ("Unknown Type");
}
Loop Operators:
while(expression) { statement }
for(expression;expression;expression) { statement }
int i = 6;
while(i>2) {
print(i);
i--;
} // This will print the numbers from 6 to 2;
for(int a=42;a<100;a++) {
print(a);
}// This will print the numbers from 42 to 100;
Input an integer number n and output the sum: 1+22+32+...+n2. Use input validation for n to be positive.
#include <alef.h>
void main(void) {
int num;
int sum=0;
int i=0;
chan(int) kbd;
alloc kbd;
proc kbdproc(kbd);
num=<-kbd;
if(num < 0) { terminate(nil);}
else {
while (i <= num) {
sum += i*i;
i++;
}
print(sum);
}
terminate(nil);
}
Functions
return type(s) function_name(param1,param2,param3...) { code }
(byte*,float) funcExample() {
print("Hi from example function");
return ("SomeText",3.14);
}
Arrays
The dimension of an array must be non-zero positive constant. Arrays have a lower bound of 0 and
an upper bound of n-1 where n is the value of the constant expression.
int intArr[2]; // Defining array with two dimensions of type int
byte chars[3] = {'A','B','C'} //Defining byte array and assigning values to its dimesions
print(someArray[2]); //Example of accesing a part of the array
Compilers
Alef has build in Compiler in the Plan 9 OS but I can not find its name in the both the Plan 9 documentation and Alef's
Projects and Software in Alef
Is said in the documentations only , that some of the Plan 9 OS system software was made with Alef, but no exact name of program.
Standard
There is no certain standart created for Alef , but it is accepted that the C style is most suitable due to the big similarities between both.