新加入的
Expected语法已经完全支持了。使用了Expected的符号会因为调用者的不同而使用不同的scope内的函数。代码如下:
首先,有main单元:
1 module main
2 import system
3 import sysutils
4 import list
5
6 func eq T :: T -> T -> bool expected
7
8 def exists e xs =
9 select xs of
10 case list x tail : if(eq e x) true (exists e tail)
11 case empty : false
12 end
13
14 def eq a b = iequ a b
15 def eq a b = fequ a b
16
17 def main score = if (flt score 60.0) "fail" "pass"
18
19 def ints = list 1 (list 2 (list 3 empty))
20 def floats = list 1.0 (list 2.0 (list 3.0 empty))
21 def chars = "vczh"
22
23 def main2 = exists 0 ints
24 def main3 = exists 0.0 floats
这里有一个eq的expected类型T->T->T->bool,然后还有两个用于整数和实数的eq函数。
其次,有main2单元:
1 module main2
2 import main
3
4 def eq a b = iequ (ord a) (ord b)
5
6 def main2 = exists 0 ints
7 def main3 = exists 0.0 floats
8 def main4 = exists 'a' chars
这里有一个用于字符的eq函数。
如果我们将def main4 = exists 'a' chars加入main模块的话则会有错误:
1 生成符号表时发生错误
2 错误[1] 模块:main 行号:10
3 信息:符号"eq"无法匹配到函数,类型:(system.char -> (system.char -> system.bool))。
因为这个时候eq存在于main2,main中的函数调用exists总是看到main中的内容。但是在main2就不同了,因为eq是expected的,main2调用的exists就可以看到main2的内容了。我们就可以看到期望的结果:
1 module main::main
2 import list
3 import system
4 import sysutils
5 func eq T :: (<T> -> (<T> -> system.bool)) expected
6 func chars :: (system.list system.char) codefrom 7
7 func eq :: (system.int -> (system.int -> system.bool)) codefrom 2
8 func eq :: (system.float -> (system.float -> system.bool)) codefrom 3
9 func exists T1 :: (<T1> -> ((system.list <T1>) -> system.bool)) codefrom 1 <Depends on expected functions>
10 func floats :: (system.list system.float) codefrom 6
11 func ints :: (system.list system.int) codefrom 5
12 func main :: (system.float -> (system.list system.char)) codefrom 4
13 func main2 :: system.bool codefrom 8
14 func main3 :: system.bool codefrom 9
15
16 【Code Unit main2】
17 module main2::main2
18 import main
19 func eq :: (system.char -> (system.char -> system.bool)) codefrom 0
20 func main2 :: system.bool codefrom 1
21 func main3 :: system.bool codefrom 2
22 func main4 :: system.bool codefrom 3
23
24 【Assembly Unit main】
25
26 [Information]
27 Name : main
28 Function Count : 10
29 Slot Count : 13
30
31 [Function]
32 Function Name : exists
33 Unique Name : [callfrom:main2]main::exists::#1
34 Owner Unit : main
35 Level : 0
36 External Command :
37 Instance : <NULL>
38
39 [Function]
40 Function Name : exists
41 Unique Name : [callfrom:main]main::exists::#1
42 Owner Unit : main
43 Level : 0
44 External Command :
45 Instance : <NULL>
46
47 [Function]
48 Function Name : chars
49 Unique Name : main::chars::#7
50 Owner Unit : main
51 Level : 0
52 External Command :
53 Instance : main::chars::#7::(system.list system.char)
54
55 [Function]
56 Function Name : eq
57 Unique Name : main::eq::#2
58 Owner Unit : main
59 Level : 0
60 External Command :
61 Instance : main::eq::#2::(system.int -> (system.int -> system.bool))
62
63 [Function]
64 Function Name : eq
65 Unique Name : main::eq::#3
66 Owner Unit : main
67 Level : 0
68 External Command :
69 Instance : main::eq::#3::(system.float -> (system.float -> system.bool))
70
71 [Function]
72 Function Name : floats
73 Unique Name : main::floats::#6
74 Owner Unit : main
75 Level : 0
76 External Command :
77 Instance : main::floats::#6::(system.list system.float)
78
79 [Function]
80 Function Name : ints
81 Unique Name : main::ints::#5
82 Owner Unit : main
83 Level : 0
84 External Command :
85 Instance : main::ints::#5::(system.list system.int)
86
87 [Function]
88 Function Name : main2
89 Unique Name : main::main2::#8
90 Owner Unit : main
91 Level : 0
92 External Command :
93 Instance : main::main2::#8::system.bool
94
95 [Function]
96 Function Name : main3
97 Unique Name : main::main3::#9
98 Owner Unit : main
99 Level : 0
100 External Command :
101 Instance : main::main3::#9::system.bool
102
103 [Function]
104 Function Name : main
105 Unique Name : main::main::#4
106 Owner Unit : main
107 Level : 0
108 External Command :
109 Instance : main::main::#4::(system.float -> (system.list system.char))
110
111 [Slot Item]
112 Unique Name : [callfrom:main2]main::exists::#1::(system.char -> ((system.list system.char) -> system.bool))
113 Parent Slot : <NULL>
114 Owner Function : [callfrom:main2]main::exists::#1
115 0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
116 1 = main2::eq::#0::(system.char -> (system.char -> system.bool))
117 2 = [callfrom:main2]main::exists::#1::(system.char -> ((system.list system.char) -> system.bool))
118
119 [Slot Item]
120 Unique Name : [callfrom:main2]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
121 Parent Slot : <NULL>
122 Owner Function : [callfrom:main2]main::exists::#1
123 0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
124 1 = main::eq::#3::(system.float -> (system.float -> system.bool))
125 2 = [callfrom:main2]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
126
127 [Slot Item]
128 Unique Name : [callfrom:main2]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
129 Parent Slot : <NULL>
130 Owner Function : [callfrom:main2]main::exists::#1
131 0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
132 1 = main::eq::#2::(system.int -> (system.int -> system.bool))
133 2 = [callfrom:main2]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
134
135 [Slot Item]
136 Unique Name : [callfrom:main]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
137 Parent Slot : <NULL>
138 Owner Function : [callfrom:main]main::exists::#1
139 0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
140 1 = main::eq::#3::(system.float -> (system.float -> system.bool))
141 2 = [callfrom:main]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
142
143 [Slot Item]
144 Unique Name : [callfrom:main]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
145 Parent Slot : <NULL>
146 Owner Function : [callfrom:main]main::exists::#1
147 0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
148 1 = main::eq::#2::(system.int -> (system.int -> system.bool))
149 2 = [callfrom:main]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
150
151 [Slot Item]
152 Unique Name : main::chars::#7::(system.list system.char)
153 Parent Slot : <NULL>
154 Owner Function : main::chars::#7
155
156 [Slot Item]
157 Unique Name : main::eq::#2::(system.int -> (system.int -> system.bool))
158 Parent Slot : <NULL>
159 Owner Function : main::eq::#2
160 3 = system::iequ::$kernelfp::iequ::(system.int -> (system.int -> system.bool))
161
162 [Slot Item]
163 Unique Name : main::eq::#3::(system.float -> (system.float -> system.bool))
164 Parent Slot : <NULL>
165 Owner Function : main::eq::#3
166 4 = system::fequ::$kernelfp::fequ::(system.float -> (system.float -> system.bool))
167
168 [Slot Item]
169 Unique Name : main::floats::#6::(system.list system.float)
170 Parent Slot : <NULL>
171 Owner Function : main::floats::#6
172
173 [Slot Item]
174 Unique Name : main::ints::#5::(system.list system.int)
175 Parent Slot : <NULL>
176 Owner Function : main::ints::#5
177
178 [Slot Item]
179 Unique Name : main::main2::#8::system.bool
180 Parent Slot : <NULL>
181 Owner Function : main::main2::#8
182 7 = [callfrom:main]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
183 8 = main::ints::#5::(system.list system.int)
184
185 [Slot Item]
186 Unique Name : main::main3::#9::system.bool
187 Parent Slot : <NULL>
188 Owner Function : main::main3::#9
189 9 = [callfrom:main]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
190 10 = main::floats::#6::(system.list system.float)
191
192 [Slot Item]
193 Unique Name : main::main::#4::(system.float -> (system.list system.char))
194 Parent Slot : <NULL>
195 Owner Function : main::main::#4
196 5 = sysutils::if::#9::(system.bool -> ((system.list system.char) -> ((system.list system.char) -> (system.list system.char))))
197 6 = system::flt::$kernelfp::flt::(system.float -> (system.float -> system.bool))
198
199 【Assembly Unit main2】
200
201 [Information]
202 Name : main2
203 Function Count : 4
204 Slot Count : 4
205
206 [Function]
207 Function Name : eq
208 Unique Name : main2::eq::#0
209 Owner Unit : main2
210 Level : 0
211 External Command :
212 Instance : main2::eq::#0::(system.char -> (system.char -> system.bool))
213
214 [Function]
215 Function Name : main2
216 Unique Name : main2::main2::#1
217 Owner Unit : main2
218 Level : 0
219 External Command :
220 Instance : main2::main2::#1::system.bool
221
222 [Function]
223 Function Name : main3
224 Unique Name : main2::main3::#2
225 Owner Unit : main2
226 Level : 0
227 External Command :
228 Instance : main2::main3::#2::system.bool
229
230 [Function]
231 Function Name : main4
232 Unique Name : main2::main4::#3
233 Owner Unit : main2
234 Level : 0
235 External Command :
236 Instance : main2::main4::#3::system.bool
237
238 [Slot Item]
239 Unique Name : main2::eq::#0::(system.char -> (system.char -> system.bool))
240 Parent Slot : <NULL>
241 Owner Function : main2::eq::#0
242 0 = system::iequ::$kernelfp::iequ::(system.int -> (system.int -> system.bool))
243 1 = system::ord::$kernelfp::ord::(system.char -> system.int)
244 2 = system::ord::$kernelfp::ord::(system.char -> system.int)
245
246 [Slot Item]
247 Unique Name : main2::main2::#1::system.bool
248 Parent Slot : <NULL>
249 Owner Function : main2::main2::#1
250 3 = [callfrom:main2]main::exists::#1::(system.int -> ((system.list system.int) -> system.bool))
251 4 = main::ints::#5::(system.list system.int)
252
253 [Slot Item]
254 Unique Name : main2::main3::#2::system.bool
255 Parent Slot : <NULL>
256 Owner Function : main2::main3::#2
257 5 = [callfrom:main2]main::exists::#1::(system.float -> ((system.list system.float) -> system.bool))
258 6 = main::floats::#6::(system.list system.float)
259
260 [Slot Item]
261 Unique Name : main2::main4::#3::system.bool
262 Parent Slot : <NULL>
263 Owner Function : main2::main4::#3
264 7 = [callfrom:main2]main::exists::#1::(system.char -> ((system.list system.char) -> system.bool))
265 8 = main::chars::#7::(system.list system.char)
我们可以看到main模块里面出现了两个不同的exists函数:
1 [Function]
2 Function Name : exists
3 Unique Name : [callfrom:main2]main::exists::#1
4 Owner Unit : main
5 Level : 0
6 External Command :
7 Instance : <NULL>
8
9 [Function]
10 Function Name : exists
11 Unique Name : [callfrom:main]main::exists::#1
12 Owner Unit : main
13 Level : 0
14 External Command :
15 Instance : <NULL>
posted on 2008-11-03 05:41
陈梓瀚(vczh) 阅读(1667)
评论(0) 编辑 收藏 引用 所属分类:
脚本技术