Debian Codegraph @

terps/tads/tads3/test/data/anonvarg.t

raw
1 /*
2 * Test of anonymous functions with varargs-list arguments. Anonymous
3 * functions and varargs-list arguments both use non-standard parameter
4 * value references, and the different special handlings interfered with
5 * one another in older versions of the compiler.
6 */
7
8 #include <tads.h>
9
10 main(args)
11 {
12 fixedfunc(1, 2);
13 varfunc(4, 5, 6);
14 varfunc2(7, 8, 9);
15 }
16
17 fixedfunc(a, b)
18 {
19 local func = {x, y: tadsSay('fixedcb: x=' + x + ', y=' + y + '\n')};
20 (func)(a, b);
21 (func)(a*2, b*2);
22 }
23
24 varfunc([args])
25 {
26 local func = new function(lst) {
27 foreach (local x in lst)
28 "\t<<x>>\n";
29 };
30
31 "varfunc: via callback\n";
32 (func)(args);
33
34 "varfunc: args.length() = <<args.length()>>\n";
35 }
36
37 varfunc2([args])
38 {
39 local func = new function(hdr) {
40 "<<hdr>>\n";
41 if (args == nil)
42 "\t<args = nil>\n";
43 else
44 foreach (local x in args)
45 "\t<<x>>\n";
46 };
47
48 (func)('varfunc2 callback:');
49
50 if (args == nil)
51 "varfunc2: args = nil\n";
52 else
53 "varfunc2: args.length() = <<args.length()>>\n";
54 }