cfad47cfa3/t3compiler/tads3/test/data/listpar.t

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
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