Changeset 771a4f7


Ignore:
Timestamp:
Nov 17, 2025, 9:00:50 PM (5 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
822ae48
Parents:
8604492
Message:

add missing Ada test program to Fangren's thesis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/fangren_yu_MMath/test.adb

    r8604492 r771a4f7  
    66        Function Random return Float is begin return 3.5; end;
    77        Function Random return Unbounded_String is begin return To_Unbounded_String( "abc" ); end;
    8        
     8
    99        Procedure Print( V : Integer ) is begin Put_Line( Integer'Image(V) ); end;
    1010        Procedure Print( V : Float ) is begin Put_Line( Float'Image(V) ); end;
    1111        Procedure Print( V : Unbounded_String ) is begin Put_Line( Ada.Strings.Unbounded.To_String(V) ); end;
    12        
     12
    1313        Function Func( V : Integer ) return Integer is begin return V; end;
    1414        Function Func( V : Float ) return Float is begin return V; end;
    1515        Function Func( V : Unbounded_String ) return Unbounded_String is begin return V; end;
    1616        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;
    1919        J : Int;
    2020        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 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        
     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
    2626        i : Integer;
    2727        f : Float;
    2828        s : Unbounded_String;
    29        
     29
    3030        Type Complex is
    31         record
    32             Re, Im : Float;
    33         end record;
     31                record
     32                Re, Im : Float;
     33                end record;
    3434        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
    3838        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;
    4141        function twice( X : T ) return T;
    42        
     42
    4343        function twice( X: T ) return T is
    4444        begin
    45            Put_Line( "XXX" ); return X + X;   -- The formal operator "*".
     45                Put_Line( "XXX" ); return X + X;        -- The formal operator "*".
    4646        end twice;
    4747
    4848        function Int_Twice is new Twice( Integer, "+" => "+" );
    4949        function float_Twice is new Twice( float, "+" => "+" );
    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;
     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;
    6161begin
    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
    7171        i := Random;
    72         Print( i );
     72        Print( i );
    7373        f := Random;
    74         Print( f );
     74        Print( f );
    7575        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
    8484        Grind( X => (Re => 1.0, Im => 1.0) );
    8585        Grind( c );
    8686        Grind( To_Unbounded_String( "abc" ) );
    87        
     87
    8888        i := Int_Twice( 2 );
    8989        Put_Line( Integer'Image(i) );
    9090        f := float_Twice( 2.5 );
    91         Print( f );
     91        Print( f );
    9292end test;
    9393
Note: See TracChangeset for help on using the changeset viewer.