-
Notifications
You must be signed in to change notification settings - Fork 76
/
can_comp.js.pe
140 lines (138 loc) · 3.49 KB
/
can_comp.js.pe
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Note:-This file is ment for tests so it is a bit verbose and hard to read
type a = def(int)->int
type g = def(int)
def unknown_type(variable):
...
enum colours:
RED = 144,
GREEN,
BLUE = 59,Other=9+GREEN
def divide(num1:int ,num2:int )->int:
match num2:
case 0:
raise error.ZeroDivisionError
case _:
return num1/num2
def decorator(func:a)->g:
h:int=9
def value(c:int):
h=8
printf("%d",h)
printf("Answer is %d",func(c))
return value
ggggggg:int=9
@decorator
def dec_test(x:int)->int:
ggggggg=7#mutability test
printf("%d",ggggggg)
@decorator
def nested_test(x:int)->int:
ggggggg=7#mutability test
printf("%d",ggggggg)
def nested_test2(x:int)->int:
ggggggg=7#mutability test
printf("%d",ggggggg)
return x*x
nested_test2(7)
return x*x
nested_test(7)
return x*x
def test(x:int)->int:#this is comment
return x
def lambda_test(x:a):
printf("The value is %d",x(5))
def func(g:int )->int:
return g
export def fun():...
type lambda_type=def(i32)->i32
def print_int(i:i32):
printf("Square is %d\n",i)
def main():
dec_test(4)
def z():
printf("hello")
z()
scope:
printf("Hello from new scope")
bddd:list=[9,7]
printf(bddd)
printf(bddd[1])
gg:dict={
"k":154,
"t":1
}
printf(gg["k"])
x:bool=False
const cc:bool =False
x=True
y:bool
y=True
if x==y:
...
printf("%d",test(0))
a:int=0
b:int=7
c:int=7
match a,b,c:
case 5,7,8:
printf("a is 5,b is 7 and c is 8")
case 4,7,_:#c can be anything
printf("a is 4 but b is 7")
break #we dont want default to execute
case 4,_,7:#b can be anything
printf("a is 4 but c is 7")
break #we dont want default to execute
case 8,_:#b and c can be anything
printf("a is 8")
case _:
printf("idk")
#optional
default:#will be executed at the end if no break
printf("Hello")
lambda_test(func)
assert 8==8
#should throw an error
#assert 8==6
printf("%d",divide(6,2))
#should terminate the program
#printf("%d",divide(6,0))
color:colours = colours.RED
print("Enum is " , color)
TernaryIf:int=5 if True else 6
assert TernaryIf==5
TernaryIf=5 if False else 6
assert TernaryIf==6
r:int=3
r--
assert r==2
r++
try:
assert r==0
except error.AssertionError:
printf("Assertion error\n")
try:
#should terminate the program
printf("%d",divide(6,0))
except error.AssertionError:...
except:
printf("Exception caught\n")
try:assert False
except error.AssertionError,error.ZeroDivisionError as e:
printf("Exception caught %d\n",e)
#TODO: Make it work with iterable and multiple function return
variable_a:int=5
variable_b:int=1
variable_b,variable_a=variable_a,variable_b
printf("variable_a is %d and variable_b is %d\n",variable_a,variable_b)
assert variable_a==1
assert variable_b==5
variable_b += variable_a
assert variable_b==6
printf("variable_b is %d\n",variable_b)
type lambda_type=def(int)->int
square:lambda_type=def(x:int):x*x
printf("Square of 4 is %d\n",square(4))
#long chained function call
print_int(square(4))
#the above is same as folows
4|>square|>print_int