Standard Built-in Modules¶
Recolon comes with several built-in modules that provide essential functions and utilities. These modules are automatically included in every Recolon program, so you don’t need to import them manually. This section will cover the key built-in modules and their functionalities.
Standard¶
These global functions are available without calling any modules:
clock()
: Returns the current system time or uptime in milliseconds. This can be used for timing events or measuring intervals.color_console("text_color", "bg_color", "string")
: Returns a string with the specified text and background colors. If either color is an empty string, the default color is used.wait_ms(milliseconds)
: Pauses the execution of the program for the specified number of milliseconds.
I/O Module (`io`)¶
The io module provides functions for basic input and output operations. These functions are essential for interacting with users, reading from files, and writing output to the console.
Reading Input
You can use the io.read_input() function to read input from the user:
log("Enter your name:");
var name = io.read_input();
log("Hello, " + name + "!");
In this example, the program prompts the user to enter their name and then greets them using the input.
File Operations
The io module also provides functions to work with files:
var content = io.file_open("example.txt");
log(content);
This code opens a file named example.txt and reads its content. You can extend this to implement file reading and writing in your programs.
Math Module (`math`)¶
The math module in Recolon provides a variety of functions and constants for mathematical operations. Below is a list of all the math functions available in Recolon, categorized for clarity.
Constants
math.pi
: The value of π (Pi).math.e
: The base of the natural logarithm, e.math.tau
: The value of τ (Tau), which is 2π.math.nan
: Represents “Not-a-Number”.
Numbers
math.floor(x)
: Returns the largest integer less than or equal tox
.math.ceil(x)
: Returns the smallest integer greater than or equal tox
.math.round(x)
: Roundsx
to the nearest integer.math.sqrt(x)
: Returns the square root ofx
.math.abs(x)
: Returns the absolute value ofx
.math.min(x, y)
: Returns the smaller of the two numbersx
andy
.math.max(x, y)
: Returns the larger of the two numbersx
andy
.math.random(x, y)
: Returns a random number betweenx
andy
.
Power & Log
math.pow(x, y)
: Returnsx
raised to the power ofy
.math.lgm(x, optional: y)
: Returns the logarithm ofx
, with an optional basey
.
Trigonometry
math.sin(x)
: Returns the sine ofx
(in radians).math.cos(x)
: Returns the cosine ofx
(in radians).math.tan(x)
: Returns the tangent ofx
(in radians).
Angular
math.degrees(x)
: Convertsx
from radians to degrees.math.radians(x)
: Convertsx
from degrees to radians.
Reserved Module Names¶
Recolon reserves the names of its built-in modules. Therefore, you cannot use these names for custom modules or variables in your programs. Attempting to use a reserved name will result in an error.
List of Reserved Module Names:
io
math
If you try to define a variable or import a module with one of these names, Recolon will throw an error. For example:
var io = "This will cause an error!";
log(io); # Error: 'io' is a reserved module name.
In this example, attempting to use io as a variable name will cause a conflict with the built-in io module.
—
Conclusion¶
The built-in modules in Recolon provide a powerful foundation for building your programs. Whether you need to perform basic input/output operations, work with files, or handle complex mathematical computations, these modules have you covered. By understanding and utilizing these modules, you can write more efficient and effective code in Recolon.