-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-compile.srm
93 lines (89 loc) · 1.95 KB
/
example-compile.srm
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from "stdlib.srm" import {
newLine, puts, getchar, putchar, midPoint, printInt, pow, modulo, newArray
};
let addArr=(arr:[Int; 2]):Int=> arr[0]+arr[1]
let mapIntArr= <T:Int>(arr:[Int; T], fn:(Int, Int):Int):[Int; T]=>{
let x:Int=0;
let newArr = newArray<T>(arr.length);
while x<arr.length{
newArr[x]=fn(arr[x], x)
x=x+1
}
newArr
}
let double=(x:Int):Int=>x*2;
type Str2<T:Int> =Str<T>;
let main=():Int => {
let hello:Str2<5> = "Hello"
let world="World"
puts("Enter 'A' for 'hello' or any other letter for 'world'\n")
let helloWorld="xxxxxxxxxxxx"
if getchar()==65{
puts(hello)
}else{
puts(world)
}
1+1
let y=3
let x:Int=0
hello=world
puts (world)
puts(hello+" galaxy")
while 5>x{
puts("abc")
x=x+1
}
{
x=0;
while x<5 {
putchar(hello[x])
x=x+1
}
newLine();
let union:Int|Null=null;
if typeof union == typeof null {
puts("null");
} else{
puts("int")
}
let arr:[Int; 3]=[4,8,7]
let arr2:[[Int; 3]; 3] = [[1,2,3],[4,5,6],[7,8,9]]
arr[1]=30
arr2[2]=arr;
arr2[0]=[4,3,2]
puts(hello)
newLine()
let f=30.0;
type Point<T> ={x:T;y:T}
let p1:Point<Float> = {x:4.0, y:3.0+f};
let p2:Point<Float> ={x:0.0, y:100.0}
p2.x=2.0;
midPoint(p1,p2)
let div=(p1.x+p2.x)/2.0;
newLine()
let touple=[1,2]
addArr(touple);
let i00=arr2[0][0]
arr2[1][1]=4
newLine();
printInt(9748);
newLine()
putchar(modulo(8, 10)+48 as Char);
newLine();
0
}
let testFn=addArr;
let testRes=testFn([4,3]);
let arr5:[Int; 5]=[4,6,8,3,9];
let doubles=mapIntArr<5>(arr5, (x:Int, i:Int):Int=>x*2);
printInt(doubles[4]);
newLine()
puts("Length of arr2 is: ")
printInt(arr2.length);
newLine()
let myArray = newArray<7>(7);
puts("The length of my array is:");
printInt(myArray.length);
newLine();
0
}