-
Notifications
You must be signed in to change notification settings - Fork 0
The Core Standard Library
The contents of this library are automatically imported into Algo on runtime. You can call all of these without using any import statements. Don't try and import this library, as it will throw an error.
Safely terminates the running Algo program, given an exit code. '0' is considered a successful execution of the program, '-1' is considered a failure. This follows C# exit code guidelines.
Parameters:
Name | Description |
---|---|
exitCode | The exit code to assign to the program upon termination. |
Usage:
//kill the program off.
terminate(0);
Returns the length of the string or list passed in.
Parameters:
Name | Description |
---|---|
x | The item to return the length of. |
Usage:
let x = [1, 2, 3];
print len(x); //3
let y = "string";
print len(y); //6
The entire string library is automatically imported in core
. To see documentation for string manipulation, click here.
Cast the given variable to a string, and returns it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to string. |
Usage:
let x = 40; //40
let y = str(x); //"40"
Cast the given variable to an integer, and returns it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to integer. |
Usage:
let x = "40"; //40
let y = int(x); //40
Cast the given variable to a rational, and return it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to rational. |
Usage:
let x = "40 / 10";
let y = rat(x); // 40/10
Cast the given variable to a float, and returns it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to float. |
Usage:
let x = "40.2323";
let y = flt(x); //40.2323
Cast the given variable to hexadecimal, and returns it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to hex. |
Usage:
let x = "40.2323";
let y = hex(x); //0x....
Cast the given variable to a bool, and return it. If the cast fails, then an error is thrown.
Parameters:
Name | Description |
---|---|
x | The variable to cast to bool. |
Usage:
let x = "false";
let y = bool(x); //false
Gets the type of a variable, and returns it. The type returned is a core.types
enum.
Parameters:
Name | Description |
---|---|
x | The variable to get the type of. |
Usage:
let x = 3; //integer
let typeOfX = typeof(x);
if (typeOfX == core.types.Integer)
{
print "this is an integer!"; //this will run.
}
An enum, listing all the possible types in Algo. Returned from typeof(x)
.
Possible Values:
String,
Integer,
Float,
Rational,
Boolean,
List,
Function,
EmulatedFunction,
Object,
Break,
Continue,
Null
Returns the index of a given item in an array. If the item is not present, -1 is returned.
Parameters:
Name | Description |
---|---|
item | The item to search for in the array. |
arr | The array to search. |
Usage:
let x = [2, 3, 4];
let twoIndex = array.indexOf(2, x); //0
Returns whether the given array contains an item.
Parameters:
Name | Description |
---|---|
item | The item to search for in the array. |
arr | The array to search. |
Usage:
let x = [2, 3, 4];
let xHasTwo = array.contains(2, x);
Algo (c) Larry Tang, 2019.
Commercial use of Algo must include the LICENSE
file in the same directory as the executable.
Standard Library Documentation: