System Module

The Language::System module provides console I/O, timing, environment access, and program control through the Console class.

xxml
#import Language::System;

Console

Static class providing standard I/O, timing, and system operations.

Output Operations

MethodParametersReturnsDescription
printmessage: String^NonePrint without newline
printLinemessage: String^NonePrint with newline
printErrormessage: String^NonePrint to stderr
printFormattedformat: String^, value: String^NoneFormatted output
clearNoneClear console screen
xxml
// Basic output
Run System::Console::printLine(String::Constructor("Hello, World!"));

// Print without newline
Run System::Console::print(String::Constructor("Enter name: "));

// Print error
Run System::Console::printError(String::Constructor("Error: file not found"));

// Formatted output
Run System::Console::printFormatted(
    String::Constructor("User: %s"),
    String::Constructor("Alice")
);

Input Operations

MethodParametersReturnsDescription
readLineString^Read line from stdin
readCharString^Read single character
readIntInteger^Read and parse integer
readFloatFloat^Read and parse float
readDoubleDouble^Read and parse double
readBoolBool^Read and parse boolean
xxml
// Read string input
Run System::Console::print(String::Constructor("Enter your name: "));
Instantiate String^ As <name> = System::Console::readLine();

// Read integer input
Run System::Console::print(String::Constructor("Enter your age: "));
Instantiate Integer^ As <age> = System::Console::readInt();

// Read boolean
Run System::Console::print(String::Constructor("Continue? (true/false): "));
Instantiate Bool^ As <continue> = System::Console::readBool();

Time Operations

MethodParametersReturnsDescription
getTimeInteger^Get current Unix timestamp (seconds)
getTimeMillisInteger^Get current time in milliseconds
sleepmilliseconds: Integer^NonePause execution
xxml
// Get current time
Instantiate Integer^ As <now> = System::Console::getTimeMillis();

// Measure execution time
Instantiate Integer^ As <start> = System::Console::getTimeMillis();

// ... do some work ...

Instantiate Integer^ As <end> = System::Console::getTimeMillis();
Instantiate Integer^ As <elapsed> = end.subtract(start);
Run System::Console::printLine(
    String::Constructor("Elapsed: ").append(elapsed.toString()).append(String::Constructor("ms"))
);

// Sleep for 1 second
Run System::Console::sleep(Integer::Constructor(1000));

Environment

MethodParametersReturnsDescription
getEnvvarName: String^String^Get environment variable
setEnvvarName: String^, value: String^Bool^Set environment variable
xxml
// Get PATH environment variable
Instantiate String^ As <path> = System::Console::getEnv(String::Constructor("PATH"));
Run System::Console::printLine(String::Constructor("PATH: ").append(path));

// Set custom variable
Instantiate Bool^ As <success> = System::Console::setEnv(
    String::Constructor("MY_APP_MODE"),
    String::Constructor("production")
);

Note

Environment variable changes only affect the current process and any child processes spawned after the change.

Program Control

MethodParametersReturnsDescription
exitexitCode: Integer^NoneTerminate program with exit code
getArgsNone^Get command line arguments
xxml
// Exit with success
Run System::Console::exit(Integer::Constructor(0));

// Exit with error
Run System::Console::exit(Integer::Constructor(1));

Warning

The exit() method immediately terminates the program. Any cleanup code after this call will not execute.

Complete Example

interactive_cli.xxml
1#import Language::Core;
2#import Language::System;
3
4[ Entrypoint
5 {
6 // Welcome message
7 Run System::Console::printLine(String::Constructor("=== XXML Calculator ==="));
8 Run System::Console::printLine(String::Constructor(""));
9
10 // Get first number
11 Run System::Console::print(String::Constructor("Enter first number: "));
12 Instantiate Integer^ As <a> = System::Console::readInt();
13
14 // Get second number
15 Run System::Console::print(String::Constructor("Enter second number: "));
16 Instantiate Integer^ As <b> = System::Console::readInt();
17
18 // Calculate and display
19 Instantiate Integer^ As <sum> = a.add(b);
20 Instantiate Integer^ As <product> = a.multiply(b);
21
22 Run System::Console::printLine(String::Constructor(""));
23 Run System::Console::printLine(
24 String::Constructor("Sum: ").append(sum.toString())
25 );
26 Run System::Console::printLine(
27 String::Constructor("Product: ").append(product.toString())
28 );
29
30 // Timing example
31 Run System::Console::printLine(String::Constructor(""));
32 Instantiate Integer^ As <timestamp> = System::Console::getTime();
33 Run System::Console::printLine(
34 String::Constructor("Timestamp: ").append(timestamp.toString())
35 );
36
37 // Environment variable
38 Instantiate String^ As <user> = System::Console::getEnv(String::Constructor("USER"));
39 Run System::Console::printLine(
40 String::Constructor("Current user: ").append(user)
41 );
42
43 Run System::Console::exit(Integer::Constructor(0));
44 }
45]

See Also