The Console API is responsible for supporting input / output via the system console (System.in/System.out).

To use this module in an ASTRA program, you must declare it using a module statement:

module Console console;

This declares that the agent will include an instance of the astra.lang.Console class and that this instance can be accessed using the console identifier. Any identifier can be used so long as it is not a reserved keyword of ASTRA.

Actions

Actions are like statements in Java – they can be used in the body of a rule. The notation for invoking an action on a module takes the form:

<module-id>.<action-signature>(<params)

For example, to print a message to the console, you would use a statement of the form:

console.println("Hello World");
Action SignatureDescription
println(X)Prints X to System.out and adds a new line.
X can be a string literal (e.g. “Hello World”) or any variable / expression that can be evaluated as a string. The toString() method is used to print out an object.
print(x)Prints X to System.out.
X can be a string literal (e.g. “Hello World”) or any variable / expression that can be evaluated as a string. The toString() method is used to print out an object.
printClassName(X)Prints out the name of the class that object X is an instance of. This method only works with Java objects (with the exclusion of Strings – which are represented in ASTRA by the string type).
readInt(X)Reads and returns an integer value from the user (the value is read from System.in)
X should be an unbound variable.
After execution, X will contain the inputted value.
readLong(X)Reads and returns a long value from the user (the value is read from System.in)
X should be an unbound variable.
After execution, X will contain the inputted value.
readFloat(X)Reads and returns a float value from the user (the value is read from System.in)
X should be an unbound variable.
After execution, X will contain the inputted value.
readDouble(X)Reads and returns a double value from the user (the value is read from System.in)
X should be an unbound variable.
After execution, X will contain the inputted value.
readString(X) Reads and returns a string value from the user (the value is read from System.in)
X should be an unbound variable.
After execution, X will contain the inputted value.