Name | Size | Type |
---|---|---|
int |
2/4 bytes | Primitive |
double |
8 bytes | Primitive |
bool |
1 byte | Primitive |
complex |
16 bytes | Primitive |
string |
variable | Object |
array |
variable | Object |
linked list |
variable | Object |
hash table |
variable | Object |
Operator | Description |
---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
% |
Modulus |
== |
Equality |
!= |
Inequality |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
! |
Logical NOT |
and |
Logical AND |
or |
Logical OR |
+= |
Additonal Assignment |
-= |
Subtraction Assignment |
*= |
Multiplication Assignment |
/= |
Division Assignment |
++ |
Increment |
-- |
Decrement |
Variables are used to store data. They are declared using the
var
keyword.
nil
.
var a = 10;
var b; // or var b = nil;
Variables can be declared in the global scope or local scope. Global variables are declared outside of any function and can be accessed from anywhere in the program. Local variables are declared inside a function and can only be accessed within that function.
var a = 10; // Global
fun foo() {
var b = 20; // Local
}
print b; // Undefined variable 'b'.
The if
statement is used to execute a block of
code
if a condition is true. If the condition is false, the code
block will not be executed. The else
statement
is
used to execute a block of code if the condition is
false.
if (condition) {
// code block
} else {
// code block
}
To check for multiple conditions, the else if
statement can be used.
if (condition1) {
// code block
} else if (condition2) {
// code block
} else {
// code block
}
Loops are used to execute a block of code multiple times. The
for
loop is used to execute a block of code a
specific number of times. The while
loop is
used to
execute a block of code as long as a condition is true.
while(condition) {
// code block
}
The for
loop is used to execute a block of code a
specific number of iterations. It has three parts: initialization,
condition, and increment/decrement.
for(var i = 0; i < 10; i++) {
// code block
}
Functions are used to group a block of code that can be
executed
multiple times. They are declared using the fun
keyword.
fun foo() {
// code block
}
Functions can take arguments. These are the values that are passed to the function when it is called.
fun foo(a, b) {
// code block
}
Functions can return a value. This is the value that the function will return when it is called.
fun foo() {
return 10;
}
Classes are used to create objects. They are declared using
the
class
keyword.
init
method. Each field is accessed under the
self
keyword.
class Person {
init(name, age){
self.name = name;
self.age = age;
}
}
Objects are instances of classes. They are created by calling the class name as a function with whichever arguments it requires.
var person = Person("John", 25);
Inheritance is used to create a new class that is based on an existing class. The new class inherits the fields and methods of the existing class.
To inherit from a class, use the<
operator.
class Student < Person {
init(name, age, grade){
self.name = name;
self.age = age;
self.grade = grade;
}
}
Note: The new Array and Float Vector semantics
([
]
and { }
respectively) are
currently experimental features added in the Jade
Release.
Arrays are used to store multiple values in a
single variable. They can either be initialized by the
array
function (which can be used to create a
dynamic
or static array) or
you can create a static array with [ ]
.
var arr1 = array(10); // Dynamic array with initial capacity of 10
var arr2 = [1, 2, 3, 4, 5]; // Static array with 5 elements
Linked lists are a Doubly Linked List that can used to store
multiple
values in a
single variable by doing operations from both the back and
front.
They can either be initialized by the
linked_list
function.
var list = linked_list();
Hash tables are used to store key-value pairs in a
single variable. They can either be initialized by the
hash_table
function. Where the key is always a
string
and the value is any type.
var table = hash_table();
Float Vectors are a special kind of static arrays, which only
store
explicitly double
values, and are able to make use
of
AVX2 instructions to do operations in parallel. When a float
vector
has a size of
3
, it is also treated as a 3D Vector. To create a
Floating Vector, you can either
use the fvec
function or you can set values
directly
with { }
.
var vec1 = fvec(3); // Float Vector with 3 elements
var vec2 = {1.0, 2.0, 3.0}; // Float Vector with 3 elements