Cranberry is a dynamically-typed interpreted language inspired by Rust, C#, Python, Javascript and Lua.
The entire language runs on the cranberry executable file. Installation instructions will be provided after.
-# ---------------------------------------------------------------------------------------------------------------------
Language Syntax
Semicolons are not required and can be used to separate different statements and expressions.
Printing
Print stuff to standard output using print and println. The latter automatically adds a newline (\n) to the end.
You can also print multiple things using commas (it will add a space between each value). ```cpp
println("Hello World")
println("foo", 123)
# Comments
Define single line only comments using hashtags (`#`). ```py
# This doesn't do anything
print("yes")
Variables
Create variables using the let keyword. You can define multiple variables using commas. ```js
let x = 10
let width, height = 20
# Functions
Create functions using the `fn` keyword followed by the arguments in parentheses. Then a code block. ```rs
fn Hello() {
println("Hello World")
}
Return values using the return keyword followed by a value.
Ranges
Like Rust, Cranberry supports Ranges which can be created using 2 numbers and the .. operator.
let range = 0..10
let range_inclusive = 0..=10
let range_stepped = 0..10..2
In the above example
rangegoes from 0 to 10 (exclusive, will stop before reaching 10)range_inclusivegoes from 0 to 10 (inclusive, will stop at 10)range_steppedgoes from 0 to 10 (exclusive, will skip by 2 each time)
Stepped is default to 1 and will become negative if the start and end positions are swapped.
Loops
Cranberry supports for, while, and loop.
For loop
Use the for keyword followed by the variable name you want and the Iterable object (string/list/range):
for i in 0..10 {
print(i)
}