fun fib(n){if(n <= 1){
ret n;}ret fib(n - 1) + fib(n - 2);}fun main(){
mut n = 10;loop{if(n < 0){break;}println(fib(n));
n -= 1;}}
Comments
// This is a single line comment
Variables
fun main(){// A variable is either const,const a = 1;// or mutable
mut b = 2;const result = a + b;print(result);// 3}
Conditions
fun main(){const a = int(input());const b = int(input());if(a > b){print("a is greater than b");}elseif(a < b){print("a is less than b");}else{print("a is equal to b");}}
Loops
fun main(){const n = int(input());
mut i = 1;loop{if(i > n){break;}println(i);
i += 1;}}
Arrays
fun main(){const arr = [1,2,3,4,5];print(arr[0]);// 1print(arr[1]);// 2print(arr[2]);// 3print(arr[3]);// 4print(arr[4]);// 5// iterateiter arr: it {
print(it);}}
Functions
fun add(a, b){
ret a + b;}
Data
data Triangle{AB,AC,BC}
methods Triangle{
fun area(){
const s = (@AB + @AC + @BC) / 2;ret pow(s *(s - @AB)*(s - @BC)*(s - @AC),0.5);}}fun main(){const triangle = Triangle{AB:4,AC:5,BC:6};println(triangle.area());}
Operators
Operator
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulo
=
Assignment
==
Equal
!=
Not equal
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
&&
Logical and
\\
Logical or
!
Logical not
+=
Increment by rhs
-=
Decrement by rhs
*=
Multiply by rhs
/=
Divide by rhs
%=
Modulo by rhs
>>
Right shift
<<
Left shift
&
Bitwise and
|
Bitwise or
^
Bitwise xor
~
Bitwise not
&=
Bitwise and by rhs
|=
Bitwise or by rhs
^=
Bitwise xor by rhs
>>=
Right shift by rhs
<<=
Left shift by rhs
Native Functions
Function
Description
Prototype
print
Prints arguments to STDOUT
fn print(..) -> None
println
print, but with newline at the end
fn println(..) -> None
sleep
Sleeps for n seconds
fn sleep(n: int/float) -> None
pop
Removes last element of given array
fn pop(arr: [any]) -> any
input
Prints prompt(if given) and takes user input as string
Yarsi: Yet another rust sys info fetcher โจ Showcase requirements ๐ cargo ๐ฆ install with $ curl https://sh.rustup.rs -sSf | sh
installation โค๏ธโ๐ฉน Ya
Mica Language reference ยท Rust API A simple, human-friendly scripting language, developed one feature at a time. Human-friendly syntax inspired by Rub