-
Notifications
You must be signed in to change notification settings - Fork 0
Imports and the Standard Library
You may have noticed in other documentation pages that import
phrases are used quite frequently. They allow you to run other Algo scripts on your filesystem, relative to the directory that you're executing in, and also allow you to import the standard library.
Let's say that I have created two files, a.ag
and b.ag
, in the same folder. If I do the following inside a.ag
:
import "b";
The entirety of script b
will run when that line is called. You can use script b
to define libraries to use, objects, or execute some commands, and they're all executed in the same scope as a.ag
.
You can also import scripts into a separate scope (execute them in a different scope) by using the as
keyword.
import "b" as c;
This creates a library c
, with the scope of b.ag
contained within it.
import
statements are also useful for using the standard library. Any files in the algo/std
directory are considered standard library files, and can be imported from anywhere on your computer, regardless of relative directories.
Warning: If you write a script that has the same name as a standard library file, it will override references to the standard library. So, don't write any scripts with the names of the ones referenced below.
The current existing standard libraries are as follows, along with a brief description of their contents. To read more about specific standard libraries, they each have individual wiki pages that will be linked here.
Name | Import Statement | Description |
---|---|---|
core | import "core" |
Contains explicit casting functions, array manipulation and more. Automatically imported. |
string | import "string" |
Contains string manipulation functions. Automatically imported inside core .
|
io | import "io" |
Contains input and output functions, like the ability to get input from console. |
json | import "json" |
Contains serializing and deserializing functions for the JSON format. |
maths | import "maths" |
Contains various mathematical functions. |
reflection | import "reflection" |
Allows you to manage (create, delete, edit) variables using their string names. |
web | import "web" |
All web functions, including server, GET, POST and other HTTP functions. |
Algo (c) Larry Tang, 2019.
Commercial use of Algo must include the LICENSE
file in the same directory as the executable.
Standard Library Documentation: