-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.arc
More file actions
21 lines (18 loc) · 764 Bytes
/
Example3.arc
File metadata and controls
21 lines (18 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Test callback functionality with Arc using functions as parameters
// This is how we define a function with a parameter that expects a function with no parameters with a return type of an integer
divide:func <- (n1:num,n2:num,callBack:func[]#nil):num => {
result:num;
is (n2 == 0) ->
yes {
@callBack(); // This is how we execute a function
}
no {
result <- n1 / n2;
}
() <- result; // This is how we return a value from a function
};
printer:func <- ():nil => { // This is how we make a function that does not return any value
$() <- "Cannot divide by 0!";
};
$() <- @divide(6,3,printer); // This is how we print the result of a function once we execute it
$() <- @divide(6,0,printer);