1 | LIB "tst.lib"; |
---|
2 | tst_init(); |
---|
3 | |
---|
4 | proc divisor_print(divisor D) |
---|
5 | { |
---|
6 | "Divisor = ("+string(D.den)+") - ("+string(D.num)+")"; |
---|
7 | } |
---|
8 | proc divisor_status(divisor D) |
---|
9 | { |
---|
10 | return ("status"); |
---|
11 | } |
---|
12 | proc divisor_test(divisor D) |
---|
13 | { |
---|
14 | return ("test"); |
---|
15 | } |
---|
16 | proc divisor_gcd(divisor D, divisor D2) |
---|
17 | { |
---|
18 | return ("gcd"); |
---|
19 | } |
---|
20 | proc divisor_extgcd(divisor D, divisor D2) |
---|
21 | { |
---|
22 | return ("extgcd"); |
---|
23 | } |
---|
24 | proc divisor_diff(divisor D, divisor D2) |
---|
25 | { |
---|
26 | return ("diff"); |
---|
27 | } |
---|
28 | |
---|
29 | newstruct("divisor","ideal den,ideal num"); |
---|
30 | newstruct("formaldivisor","list summands"); |
---|
31 | newstruct("pdivisor","list summands, cone tail"); |
---|
32 | |
---|
33 | system("install","divisor","status",divisor_status, 4); |
---|
34 | system("install","divisor","test",divisor_test,4); |
---|
35 | system("install","divisor","gcd",divisor_gcd,2); |
---|
36 | system("install","divisor","extgcd",divisor_extgcd,2); |
---|
37 | |
---|
38 | |
---|
39 | system("install","divisor","print",divisor_print,1); |
---|
40 | |
---|
41 | ring r=0,(x,y),dp; |
---|
42 | |
---|
43 | divisor C; |
---|
44 | C.num = ideal(x); |
---|
45 | C.den = ideal(y); |
---|
46 | |
---|
47 | C; |
---|
48 | test(C); |
---|
49 | status(C); |
---|
50 | gcd(C,C); |
---|
51 | extgcd(C,C); |
---|
52 | // ------------------------------------------------------- |
---|
53 | newstruct("myunion", "poly p,int i"); |
---|
54 | proc to_poly(myunion uni) |
---|
55 | { |
---|
56 | return (uni.p); |
---|
57 | } |
---|
58 | |
---|
59 | proc to_int(myunion uni) |
---|
60 | { |
---|
61 | return (uni.i); |
---|
62 | } |
---|
63 | |
---|
64 | ring r=0,x,dp; |
---|
65 | |
---|
66 | myunion uni; |
---|
67 | uni.p = x+1; |
---|
68 | uni.i = 17; |
---|
69 | |
---|
70 | system("install", "myunion", "poly", to_poly, 1); |
---|
71 | system("install", "myunion", "int", to_int, 1); |
---|
72 | |
---|
73 | poly(uni); // -> x+1 |
---|
74 | int(uni); // -> 17 |
---|
75 | |
---|
76 | // --------------------------------------------------------- |
---|
77 | |
---|
78 | newstruct("stringifiable", "int i"); |
---|
79 | stringifiable stry; |
---|
80 | stry; |
---|
81 | string(stry); |
---|
82 | |
---|
83 | proc to_str(def arg) { return ("(overloaded)"); } |
---|
84 | system("install", "stringifiable", "string", to_str,1); |
---|
85 | stry; // print falls back to string |
---|
86 | string(stry); |
---|
87 | |
---|
88 | proc to_str_wrong(def arg) { return (17); } |
---|
89 | system("install", "stringifiable", "string", to_str_wrong,1); |
---|
90 | stry; // incorrectly converted, fall back to default |
---|
91 | string(stry); |
---|
92 | |
---|
93 | proc printing(def arg) { ("(overloaded)"); } |
---|
94 | system("install", "stringifiable", "print", printing,1); |
---|
95 | |
---|
96 | stry; // now only print works correctly |
---|
97 | string(stry); // incorrectly converted, fall back to default |
---|
98 | |
---|
99 | tst_status(1);$ |
---|