It is necessary to qualify module names with the appropriate module handle. To make Limbo code less verbose, you can use the import statement to bring the specified types and functions into the current scope. For example, using import would change the above code to look like:
sys := load Sys Sys->PATH;
print: import sys;
print("Hello, World!\n");
The import statement conventionally follows the include statement or the handle declaration statement. This gives the imported data or function global scope within the module (accessible to all functions within the module). For example, we could change the Greet program to import the print function:
Program Listing 3-5 greetimport.b
implement Command;
include "sys.m";
include "draw.m";
sys: Sys;
print: import sys;
Command: module {
init: fn(ctxt: ref Draw->Context, argv: list of string);
};
init(ctxt: ref Draw->Context, argv: list of string) {
sys = load Sys Sys->PATH;
if ((tl argv) != nil)
print("Hello, %s!\n", hd (tl argv));
else
print("Hello, World!\n");
}
On Line 7, the
import statement follows the Sys module handle declaration (Line 6). The function can then be accessed like a local function, without the module handle qualifier (Lines 16 and 18).