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
| Method | Parameters | Returns | Description |
|---|---|---|---|
| message: String^ | None | Print without newline | |
| printLine | message: String^ | None | Print with newline |
| printError | message: String^ | None | Print to stderr |
| printFormatted | format: String^, value: String^ | None | Formatted output |
| clear | — | None | Clear 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
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readLine | — | String^ | Read line from stdin |
| readChar | — | String^ | Read single character |
| readInt | — | Integer^ | Read and parse integer |
| readFloat | — | Float^ | Read and parse float |
| readDouble | — | Double^ | Read and parse double |
| readBool | — | Bool^ | 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
| Method | Parameters | Returns | Description |
|---|---|---|---|
| getTime | — | Integer^ | Get current Unix timestamp (seconds) |
| getTimeMillis | — | Integer^ | Get current time in milliseconds |
| sleep | milliseconds: Integer^ | None | Pause 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
| Method | Parameters | Returns | Description |
|---|---|---|---|
| getEnv | varName: String^ | String^ | Get environment variable |
| setEnv | varName: 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
| Method | Parameters | Returns | Description |
|---|---|---|---|
| exit | exitCode: Integer^ | None | Terminate program with exit code |
| getArgs | — | None^ | 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 ]