Cherry is a multi-purpose programming language developed as a passion project. My goal is to create a language that feels familiar yet distinctly unique. A language that I would enjoy using myself.
Currently, Cherry is very much a work in progress. This documentation outlines my plans for the direction this language will go. Hopefully in reading it, you’ll be able to get a grasp of what my vision is. Please keep in mind things can change but, I’d love any feedback.
The first and most iconic program to create in a new language, hello world! Create a file with the extension ch
in your root directory and paste the code below.
@pckg root;
@imp * from "std/io";
public {
func main(): void {
println("Hello, world!");
}
}
If you run this file and it prints the text correctly, everything has been setup properly!
Cherry is statically typed which means you have to specifically define variable types.
int // Integer 64-bit
float // Floating-point 64-bit
bool // Boolean
string // String
int[] // Array
int x = 10;
float y = 25.5f;
string name = "William";
bool b = true; // or false
string[] fruits = ["Cherry", "Banana", "Apple", "Grape"];
string myFruit = fruits[1];
int len = myFruits.length;
const float b = 20.5; // Immutable variable
Cherry passes all values by value by default. This means data structures are deep copied when passed into functions or reassigned. If you want to avoid unnecessary copies and pass the original reference, you can use pointers with the *
symbol
int x = 10;
int* ptr = &x; // Get the pointer to x
*ptr = 20; // Dereference and modify
println(x); // Prints: 20
By default, values cannot be null. To create a variable that can be given a null value, postfix it with a ?
symbol.
string name = "William"; // Can only be string
string? name = "William"; // Can be string or null