4 min read, 1040 words
Adrift in Limbo
We have trot upon foreign ground, onto the lands of a country unknown — Let us being studying its language. Thus, I believe it is time to shortly investigate the intricacies behind the programming language this operating system has been written in and wherewith one may create one’s own programs for it — Limbo; truly, the name, once more, appears to have been derived from Dante’s works — a matter I should not be too astonished over — and bears strong resemblance to the language used in the creation of the Unix system, namely C.
Unfortunately, I must admit with great sorrow, I am but a mere novice regarding this intriguing programming language; indeed, I have but very little knowledge of the C programming language either. Therefore, I found it pertinent to add this disclaimer here, as the forthcoming examples may not have been written or explained in the best of manners and I hence urge you to consider the study of a book dedicated solely to the topic of programming if you wish to learn more than but the simplest of aspects of this language.
Nevertheless, I shall herein attempt to teach you the very basics of this programming language so that, should you wish to continue your study of it, you will not dive into a more advanced book without any prior knowledge; this, I dearly hope, will greatly decrease the burden of attempting to read a more advanced book on this subject and thenceforth ease your journey in becoming more knowledgable.
Additionally, I shall be henceforth assume that you possess a very elemental understanding of computer programming; nonetheless, I strive to write everything in a way that even a layman may grasp the majority of the subject by attempting to unravel terms and concepts that may not be known to a large portion of the population. Please be aware, however, that to follow the upcoming chapter properly, you will require a working Inferno installation; it is possible to simply read along — I shall provide everything that is necessary to follow this chapter without the need to have Inferno installed —, yet it would be beneficial to follow along and experiment with the code yourself.
Lastly, I greatly encourage you to glance at the Further Reading section of this book, for therein you shall be presented with my personal recommendations for furthering your wisdom regarding both the operating system and the programming language wherewith it was forged.
Firstly, it is paramount to understand a Limbo program’s underlying structure, for it may differ somewhat from other programming languages; yet, Limbo’s syntax reminds me greatly of that of the C programming language — whereof, I believe, it was inspired. Nevertheless, there are a number of differences — for, otherwise, it would be but a mere clone of C and not a new language altogether — and should you know C, you may find a large amount of the upcoming code familiar, yet alien at the same time.
Programs written in Limbo are comprised of modules which connect with one another to perform tasks. Each module is further partitioned into two separate entities, every one thereof having their own, distinct function, namely the module implementation and the module declaration, which customarily reside in their own, distinct file; the module declaration being stored inside an .m file and the module implementation in a .b file. Typically, having an entire module be stored within just one file should be avoided for anything but the simplest of programs.
The module declaration contains the functions and constants that are to be made publicly available, whereafter other modules may access them with ease; the implementation contains the actual code to be executed and is thus, generally, the file comprised of the largest amount of lines. A module is not required to have but one mere implementation and frequently possesses several, each stored inside their own .b file.
Additionally, Limbo’s ability can be greatly enhanced with the help of libraries, whereof a small number of vital ones have been included within the Inferno kernel, such as Sys, providing system-related functions, such as print, wherewith one may print text onto the screen; and Draw and Tk which may be used to create graphical interfaces. Additional libraries can be loaded to further increase the capabilities of Limbo and add features that would otherwise be much to arduous to program oneself.
Let us look at a program written by the majority of programmers when they begin their study of a particular programming language, a Hello World program; its intent is to simply print the words Hello World on screen. To do so, create a new file titled hello_world.b and add the following contents: —
# hello_world.b
implement HelloWorld;
include "sys.m";
include "draw.m";
sys: Sys;
HelloWorld: module {
init: fn(ctxt: ref Draw->Context, args: list of string);
};
init(ctxt: ref Draw->Context, args: list of string) {
sys = load Sys Sys->PATH;
sys->print("Hello, World!\n");
}
You may use the previously discussed Edit or Acme programs to create and save this file directly within Inferno itself, whereupon you may save it and open a new shell; therein you must find the directory whence your program has gone and type the following command limbo -g hello_world.g. Thereupon, a new file will be constructed simply titled hello_world and to execute it you must type hello_world into the shell window; you shall then be greeted by a “Hello, World!”.
We shall now begin examining each line of this program separately, so that we may comprehend how this intriguing language functions; for merely copying and pasting a program’s code will not allow us to fully — or, indeed, at all — grasp its underlying structure.