Ticket #70: default_arg.txt

File default_arg.txt, 1.4 KB (added by seelisch, 14 years ago)

Singular-executable file

Line 
1proc set_defaults(list t)
2{
3     attrib(test_proc_1, "default_arg", t);
4     attrib(test_proc_2, "default_arg", t);
5     attrib(test_proc_3, "default_arg", t);
6}
7
8proc test_all()
9{
10     test_proc_1(17);
11     test_proc_2();
12     test_proc_3();
13}
14
15proc test_proc_1 (int i, list #)
16"test 1 for default argument list"
17{
18     "proc test_proc_1:";
19     "   square of first argument:", i*i;
20     "   further arguments:";
21     if (size(#)==0) {"      none";}
22     else {
23        for (int k = 1; k <= size(#); k = k + 1) {
24           "      default argument at index", k, ":",#[k];
25        }
26     }
27}
28
29proc test_proc_2
30//"test 2 for default argument list"
31{
32     "proc test_proc_2:";
33     "   arguments:";
34     if (size(#)==0) {"      none";}
35     else {
36        for (int k = 1; k <= size(#); k = k + 1) {
37           "      default argument at index", k, ":",#[k];
38        }
39     }
40}
41
42proc test_proc_3 (list #)
43"test 3 for default argument list"
44{
45     "proc test_proc_3:";
46     "   arguments:";
47     if (size(#)==0) {"      none";}
48     else {
49        for (int k = 1; k <= size(#); k = k + 1) {
50           "      default argument at index", k, ":",#[k];
51        }
52     }
53}
54
55ring r = (0), (x, y, z), dp;
56
57list l = 4, 2, "a", 67, x;
58set_defaults(l);
59test_all();
60
61list l;
62set_defaults(l);
63test_all();
64
65list l = -y*y+z*x*y+x*x;
66set_defaults(l);
67test_all();