Changeset 771a4f7
- Timestamp:
- Nov 17, 2025, 9:00:50 PM (5 weeks ago)
- Branches:
- master
- Children:
- 822ae48
- Parents:
- 8604492
- File:
-
- 1 edited
-
doc/theses/fangren_yu_MMath/test.adb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/fangren_yu_MMath/test.adb
r8604492 r771a4f7 6 6 Function Random return Float is begin return 3.5; end; 7 7 Function Random return Unbounded_String is begin return To_Unbounded_String( "abc" ); end; 8 8 9 9 Procedure Print( V : Integer ) is begin Put_Line( Integer'Image(V) ); end; 10 10 Procedure Print( V : Float ) is begin Put_Line( Float'Image(V) ); end; 11 11 Procedure Print( V : Unbounded_String ) is begin Put_Line( Ada.Strings.Unbounded.To_String(V) ); end; 12 12 13 13 Function Func( V : Integer ) return Integer is begin return V; end; 14 14 Function Func( V : Float ) return Float is begin return V; end; 15 15 Function Func( V : Unbounded_String ) return Unbounded_String is begin return V; end; 16 16 Function Func( V1 : Integer; V2 : Float ) return Float is begin return Float(V1) + V2; end; 17 18 subtype Int is Integer;17 18 subtype Int is Integer; 19 19 J : Int; 20 20 Function "-"( L, R : Int ) return Int is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion 21 22 -- duplicate body for "-" declared at line 2023 -- subtype SInt is Integer range -10 .. 10;24 -- Function "-"( L, R : SInt ) return SInt is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion25 21 22 -- duplicate body for "-" declared at line 20 23 -- subtype SInt is Integer range -10 .. 10; 24 -- Function "-"( L, R : SInt ) return SInt is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion 25 26 26 i : Integer; 27 27 f : Float; 28 28 s : Unbounded_String; 29 29 30 30 Type Complex is 31 record32 Re, Im : Float;33 end record;31 record 32 Re, Im : Float; 33 end record; 34 34 c : Complex := (Re => 1.0, Im => 1.0); 35 Procedure Grind (X : Complex) is begin Put_Line( "Grind1" ); end;36 Procedure Grind (X : Unbounded_String) is begin Put_Line( "Grind2" ); end;37 35 Procedure Grind (X : Complex) is begin Put_Line( "Grind1" ); end; 36 Procedure Grind (X : Unbounded_String) is begin Put_Line( "Grind2" ); end; 37 38 38 generic 39 type T is private;40 with function "+"( X, Y: T ) return T;39 type T is private; 40 with function "+"( X, Y: T ) return T; 41 41 function twice( X : T ) return T; 42 42 43 43 function twice( X: T ) return T is 44 44 begin 45 Put_Line( "XXX" ); return X + X;-- The formal operator "*".45 Put_Line( "XXX" ); return X + X; -- The formal operator "*". 46 46 end twice; 47 47 48 48 function Int_Twice is new Twice( Integer, "+" => "+" ); 49 49 function float_Twice is new Twice( float, "+" => "+" ); 50 51 -- generic units cannot be overloaded52 -- generic53 --type T is private;54 --with function "+"( X, Y: T ) return T;55 -- function twice( X : T; Y : T ) return T;56 57 -- function twice( X: T; Y : T ) return T is58 -- begin59 -- Put_Line( "XXX" ); return X + X;-- The formal operator "*".60 -- end twice;50 51 -- generic units cannot be overloaded 52 -- generic 53 -- type T is private; 54 -- with function "+"( X, Y: T ) return T; 55 -- function twice( X : T; Y : T ) return T; 56 57 -- function twice( X: T; Y : T ) return T is 58 -- begin 59 -- Put_Line( "XXX" ); return X + X; -- The formal operator "*". 60 -- end twice; 61 61 begin 62 I := 3;63 I := 7 - 3;64 Print( i );65 F := 3.8;66 I := 7 - 2;67 Print( i );68 J := 7 - 3;69 Print( j );70 62 I := 3; 63 I := 7 - 3; 64 Print( i ); 65 F := 3.8; 66 I := 7 - 2; 67 Print( i ); 68 J := 7 - 3; 69 Print( j ); 70 71 71 i := Random; 72 Print( i );72 Print( i ); 73 73 f := Random; 74 Print( f );74 Print( f ); 75 75 s := Random; 76 Print( s );77 78 Print( Func( V => 7 ) );79 Print( Func( 7.5 ) );80 Print( Func( To_Unbounded_String( "abc" ) ) );81 Print( Func( 3, 3.5 ) );82 --Print( Func( 3, 3 ) );83 76 Print( s ); 77 78 Print( Func( V => 7 ) ); 79 Print( Func( 7.5 ) ); 80 Print( Func( To_Unbounded_String( "abc" ) ) ); 81 Print( Func( 3, 3.5 ) ); 82 -- Print( Func( 3, 3 ) ); 83 84 84 Grind( X => (Re => 1.0, Im => 1.0) ); 85 85 Grind( c ); 86 86 Grind( To_Unbounded_String( "abc" ) ); 87 87 88 88 i := Int_Twice( 2 ); 89 89 Put_Line( Integer'Image(i) ); 90 90 f := float_Twice( 2.5 ); 91 Print( f );91 Print( f ); 92 92 end test; 93 93
Note:
See TracChangeset
for help on using the changeset viewer.