-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.txt
172 lines (113 loc) · 3.33 KB
/
input.txt
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# 1. trait definition
# the following trait definition says that
# typename 'self' should support .append(x) and .pop() operation
# and __len__ method
trait any(self):
pass
trait StackLike(self):
fn:
append(self, any) -> [self or None]
pop(self) -> [self or None]
popop(self) -> [self or (None and None)]
fn:
__len__(self) -> int
# the following trait definition says that
# the instance of the class 'self' should have 'x', 'y' member variables
trait PointLike(self):
var:
x: int
y: int
trait AnyRandom(self):
var:
x: int
y: int
z
fn:
__init__(self, =int, =int, =any) -> None
cls_fn:
foo(cls, int) -> str
foo(cls, float)
cls_var:
xxx
yyy: int
static_fn:
bar() -> None
printinfo trait_of(AnyRandom.x)
t_random = any_random
trait decl_var_with_comma(self):
var:
[x, y, z]: int
# 2. traits with 2 or more parameters.
trait Addable(self, T):
fn:
__add__(self, T) -> self
trait Multipliable(self, T):
fn:
__mul__(self, T) -> self
# 3. trait(type) expression is evaluated as a boolean.
printinfo StackLike(int) # -> False
printinfo StackLike(list) # -> True
printinfo Addable(str, int) # -> False
printinfo Multipliable(str, int) # -> True, since "str" * 3 is a valid expression
# 4. If you want to bind some arguments to a trait, use trait[]() expression.
printinfo Addable[int](str) # -> False, exactly same meaning with Addable(str, int)
# 6. trait extensions.
trait AddableSubable(self, T) extends Addable[T]:
fn:
__sub__(self, T)
# 7. printinfo operator.
trait Fooable(self):
fn:
foo(self, any)
printinfo Fooable
# possible output:
# """
# trait Fooable supports:
# member function .foo(any)
# """
# 8. trait and/or/not operator.
trait FooBarable(self):
fn:
foo(self, any)
bar(self, any)
trait BarBazable(self):
fn:
bar(self, any)
baz(self, any)
printinfo [FooBarable and BarBazable]
# possible output:
# """
# trait (unnamed @ line 88) supports:
# member function .foo(any)
# member function .bar(any)
# member function .baz(any)
# """
printinfo [FooBarable or BarBazable]
# possible output:
# """
# trait (unnamed @ line 98) supports:
# member function .bar(any)
# """
# 11. generate operator.
generate Fooo
generate FooBarable
# 12. implies operator.
printinfo [FooBarable and BarBazable] implies [FooBarable or BarBazable] # -> True
# 13. assignments.
a, b = b, a
# 14. default arguments.
trait DefaultArgsExample(self, arg_a, arg_b, arg_c=[Addable and Subable], arg_d=float):
pass
trait TraitWithAllOptionalArgs(self, arg_a=int, arg_b=str):
fn:
whatever(self, int, int, =int, =int, *, a:=int, b:int)
# 15. traits with generic type variable.
trait GenericTrait(self):
fn:
foo[T](self, T) -> T
trait vector7D(self) extends vector[vector[vector[vector[vector[vector[vector[int]]]]]]]:
fn:
begin(self) -> iterator[vector[any] or vector[vector[any] or any] or vector[vector[vector[any]]]]
end(self) -> iterator[int or [trait_of(vector.a)] and trait_of([None or vector5D[v[u], v[u]]].y)]
front(self, =[int or (str and not float or vector[int])])
printinfo (trait_of(x.z) implies trait_of(y.z)) and (True == False or False != int(int))