Occult has 16 keywords in the language, which makes it fairly simple to learn.
fn if else elseif loop when do return break continue while for include in true
The "elseif" keyword can also be written as 2 separate words.
Occult also has a basic type system for now, and these are the only supported types as of now.
i64 i32 i16 i8 u64 u32 u16 u8 f64 f32 bool char string array
There will be other additions in the future, such as generics, and other things which a modern language would use.
Here is an example on how to write a function.
fn add ( i64 x , i64 y ) i64 {
return x + y ;
}
fn main ( ) i64 {
return add ( 10 , 30 ) ;
}
Occult does not have a void type! Functions such as the main function rely on an integer type.
Control flow is like any other language.
Arrays are nice and simple to write, with for loops!
fn main ( ) i64 {
array [ 5 ] i64 arr_test = { 1 , 2 , 3 , 4 , 5 } ;
i64 sum = 0 ;
for i64 i = 0 when i < 5 do i = i + 1 {
sum = sum + arr_test [ i ] ;
}
return sum ;
}
Here's a 2d array sample with foreach loops!
fn return_2d_array ( ) array [ ] [ ] i64 {
array [ 2 ] [ 2 ] i64 test_2d = { { 1 , 2 } , { 3 , 4 } } ;
return test_2d ;
}
fn main ( ) i64 {
array [ 2 ] [ 2 ] res_array = return_2d_array ( ) ;
i64 sum = 0 ;
for array [ ] i64 r in res_array {
for i64 c in res_array {
sum = sum + c ;
}
}
return sum ;
}
Here is a loop sample!
fn main ( ) i64 {
i64 x = 0 ;
i64 result = 0 ;
loop {
if x == 5 {
break ;
}
x = x + 1 ;
if x == 3 {
continue ;
}
else {
result = result + x ;
result = result + x ;
}
}
return result ;
}
While loops through fibonacci!
fn fib ( i64 n ) i64 {
i64 n1 = 0 ;
i64 n2 = 1 ;
i64 i = 0 ;
while i < n {
i64 next = n1 + n2 ;
n1 = n2 ;
n2 = next ;
i = i + 1 ;
}
return n1 ;
}
fn main ( ) i64 {
return fib ( 40 ) ;
}
And lastly, here is a basic recursion example, with some if statements!
fn gcd ( i64 a , i64 b ) i64 {
if a == b {
return a ;
}
elseif a > b {
return gcd ( a - b , b ) ;
}
else {
return gcd ( a , b - a ) ;
}
}
fn main ( ) i64 {
return gcd ( 48 , 18 ) ;
}
W.I.P
W.I.P
W.I.P