Coal is a programming language designed for simplicity and ease of use. It is a compiled language, meaning that it runs faster than python. Coal also has the low-level accessibility like C.
- Simple syntax
- Fast execution
- Low-level accessibility
- Easy to learn
Variables are declared by using the var keyword like in kotlin:
var x = 5 // int
var y: string = "Hello, World!"
When creating a variable, you have the option to declare a type. You must always assign a type if you leave the variable undeclared, otherwise the compilier will figure out the type for you.
See the Data Types section for more information.
Coal supports the following data types:
- int
- float
- string
- bool
- char
We hope to have more in the future!
Functions are declared using the fn keyword:
fn main() {
// code here
}
At the moment, you cannot make any other functions other than the main function. (We plan to add this soon.)
Important: All coal files always start with a main function, which is the entry point of the program.
fn main() {
var x = 5
if(x == 5) {
println("x = 5")
} elif(x != 5 && x >= 10) {
println("x isnt 5 and is greater than 10")
} else {
println("x isnt 5 and is less than 10")
}
}
fn main() {
var x = 0
while(x < 100_000) {
x += 1
println(x)
}
println("We're done!")
}
To print to the console, use the println function:
println("Hello, World!")
To take input from the user, use the input function:
var name = input("What's your name? ")
Coming soon!
Coal supports the following mathematical operations:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Modulus: %
More coming soon!
To compile and run a coal program, use the following command:
./gradlew run --args="--input path/to/your/file.coal"
This will compile a coal program that will appear in the same directory. It is important to note that when building if there is an error in your code, the compiler will not tell you what is wrong. (We hope to add this feature however we don't know.)