-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest
110 lines (97 loc) · 1.38 KB
/
test
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
// 分支条件
even = 0
odd = 0
sum = 0
i = 1
while i < 10 {
if i % 2 == 0 { // event number ?
even = even + i
} else {
odd = odd + i
}
sum = sum + (i + 1)
i = i + 1
}
print(even)
print("\n")
print(-odd)
print("\n")
// 字符串数字相加
print("sum = " + sum)
print("\n")
print("Hello " + "World " + sum)
print("\n")
// 函数
def fib(n) {
if n < 2 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
print("fib(10) == " + fib(10))
print("\n")
// 闭包
def add(c) {
func (x) { c = c + x }
}
print(add(1)(10))
print("\n")
print(c1 = add(1))
print("\n")
print(c1(2))
print("\n")
// 内置函数
print(size("test"))
print("\n")
print("print return " + itoa(print("Hello " + "World!\n")))
print("\n")
print(timestamp())
print("\n")
print(atoi("12345"))
print("\n")
// 数组
print(a = [1, 2, 3, 4, 5])
print("\n")
a[1] = 2
print(a[1])
print("\n")
a[0]
a[4]
// 类
class Animal {
age = 0
weight = 100
c = [1, 3, 5]
def info() {
"father info"
}
def father() {
"father test"
}
}
// 继承
class Dog extends Animal {
def info() {
"age = " + age + "; weight = " + weight
}
}
d = Dog.new
d.age = 1
print(d.info())
print("\n")
print(d.weight)
print("\n")
print(d.father())
print("\n")
d.c
d.info
c = d
print(d)
print("\n")
print(c)
print("\n")
// 终端输入
while 1 {
print(read())
}