This repository was archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsample.zem
73 lines (62 loc) · 1.53 KB
/
sample.zem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* @author Cameron Zemek <[email protected]>
*/
// This script is an example of a simple language.
// There are only three basic data types: numbers, strings, boolean
a_number = 3 ^ 2;
a_string = "hello";
a_bool = true;
// Operators
concat_string = "hello" ~ " " ~ "world.";
fav_string = 3 ~ " is my favourite number";
result_number = 1 + 2 - 1 * 5 / 3.2 + 2^2;
isEmail = true;
someOtherBoolean = false;
condition = isEmail && (len(a_string) > 0) || someOtherBoolean;
// if control flow
if (a_number < 3) {
println("number is less then 3");
} else if (a_number == 3) {
println("number is 3");
} else {
println("number is greater then 3");
}
// while loop
counter = 1;
length = 9;
while (counter <= length) {
counter = counter + 1;
}
// Arrays
my_list = ["apple", "banana", "orange"];
println("list[1]: " ~ my_list[1]);
my_list[1] = "pear";
// foreach loop
foreach (my_list as item) {
println(item);
}
// Dictionary
dict = {"fruit" : "apple", "veggie" : "pumpkin"};
println("fruit: " ~ dict["fruit"]);
dict["fruit"] = "orange";
foreach (dict as key : value) {
println(key ~ ": " ~ value);
}
// Defining functions
sum = function(list_of_numbers) {
total = 0;
foreach (list_of_numbers as number) {
total = total + number;
}
};
range = function(start_number, end_number, step = 1) {
result = [];
number = start_number;
while (number <= end_number) {
array_push(result, number);
number = number + step;
}
return result;
};
// Calling functions
println(sum(range(1, 9)));