AILang Documentation

Welcome to the official documentation for AILang, SmathyCo's revolutionary AI programming language.

AILang is designed for simplicity and easy learning, allowing you to integrate and control AI models with clear code. It offers an intuitive syntax that abstracts away the complexities of machine learning frameworks, letting you focus on building intelligent applications. Whether you're a seasoned AI practitioner or just starting, AILang provides the tools to bring your AI ideas to life efficiently.

About

AILang is designed for simplicity and easy learning, allowing you to integrate and control AI models with clear code. Follow these steps to begin your journey with AILang.

Installation

To install AILang, you will need to download the binaries.

Download AILang Binaries

When done with the download, you can now unzip the folder inside your code editor's new project.

Now you will see 3 binary files. Use the one that works with your operating system.

To use them, you simply need to run the file as an executable in a command line interface. Here is an example for Windows 10.

.\ailang-win.exe <specify here your .ailang file path>

Your First AILang Program

Let's write a simple program that uses a function that prompts the user his name to send him a greeting only if a name is entered. Create a file named greet.ailang:

task askName() {
    print("What is your name?");
    name = readln(); // Read the name inside the function

    if (name) { // Check if the name is not empty
        print("Hello " + name + " welcome to AILang!");
    } else {
        print("Please enter your name.");
        askName(); // Call itself to repeat the process
    }
}

// Start the process
askName();

To run this program on Windows, execute the following command in your terminal:

.\ailang-win.exe ./greet.ailang

Here is the output.

What is your name?
Smathy
Hello Smathy welcome to AILang!

Variables and Data Types

AILang supports standard data types like strings, numbers, booleans, lists and objects. Variables are declared like the following.

myString = "Hello, AILang!"; // String
myNumber = 123;           // Number
isTrue = true;            // Boolean
myList = ["item1", "item2", "item3"]; // List (Array)
myObject = {"item1": "item1Value"}; // Object

Functions (Tasks)

Define functions using the task keyword. Functions can take arguments and return values using the return statement.

task addNumbers(a, b) {
    return a + b;
}

print(addNumbers(5, 10)); // Output: 15

Len

To get the length of a string you can use the len keyword as followed.

x = "Hello!";

print(len(x)); // Output: 6

Read / Write Files

To read or write a file, you can use the built-in read and write functions. The write function takes a file path and a string of content to write. The read function takes a file path and returns the content of the file as a string. To handle potential errors, such as a file not existing, it's best to wrap the read call in a try...catch block.

write("my_data.txt", "Hello, this is a test file!");

print("Successfully wrote to my_data.txt");


try {
    content = read("my_data.txt");
    
    print(content);
} catch (e) {
    print("Error reading the file: " + e);
}

For Loop

To create a for loop you can use the for...in keywords as followed.

x = [0, 1, 2, 3, 4, 5];

for (test in x) {
    print(test);
}

Output:

0
1
2
3
4
5

Error Handling

Implement robust error handling in your AILang programs using try-catch blocks to gracefully manage exceptions during AI model interactions or other operations.

try {
    x = 1;
    print("Hello, world!");
} catch (e) {
    print("Error: " + e);
}

Contains

To check if something contains something you can use the contains keyword as followed.

print(contains("testing", "test")); // Output: true

if (contains("testing", "test")) {
    print("testing contains test");
} else {
    print("testing doesn't contain test");
}
// Output: testing contains test