Debian Codegraph @

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

raw
1 /*
2 * list varargs parameters
3 */
4
5 #include "tads.h"
6 #include "t3.h"
7
8 class RuntimeError: object
9 construct(errno, ...) { errno_ = errno; }
10 display = "Runtime error: <<exceptionMessage>>"
11 errno_ = 0
12 exceptionMessage = ''
13 ;
14
15 _say_embed(str) { tadsSay(str); }
16
17 _main(args)
18 {
19 try
20 {
21 t3SetSay(_say_embed);
22 main(args);
23 }
24 catch (RuntimeError rte)
25 {
26 "\n<<rte.display>>\n";
27 }
28 }
29
30 main(args)
31 {
32 func(9);
33 func(8, 2);
34 func(7, 2, 3);
35 func(6, 2, 3, 4);
36 }
37
38 func(a, [b])
39 {
40 "func: a = <<a>>, b = <<sayList(b)>>\n";
41 func2(b..., a);
42 func2(a, b...);
43 }
44
45 func2([x])
46 {
47 "+ func2: x = <<sayList(x)>>\n";
48 }
49
50 sayList(lst)
51 {
52 if (lst == nil)
53 {
54 "nil";
55 }
56 else
57 {
58 "[";
59 for (local i = 1, local len = lst.length() ; i <= len ; ++i)
60 {
61 if (i != 1)
62 ", ";
63 tadsSay(lst[i]);
64 }
65 "]";
66 }
67 }
68