source: doc/theses/fangren_yu_MMath/test.swift @ f5bf3c2

Last change on this file since f5bf3c2 was 4d5c5b6a, checked in by Peter A. Buhr <pabuhr@…>, 6 weeks ago

add overload table data for Ada

  • Property mode set to 100644
File size: 1000 bytes
Line 
1// overloading on return type
2func random() -> Int{ 3; }
3func random() -> String{ "abc"; }
4func random() -> Double{ 3.5; }
5var r1 : Int = random();
6print( r1 );
7var r2 : String = random();
8print( r2 );
9var r3 : Double = random();
10print( r3 );
11
12// overloading functions without parameter names
13func fun( _ x : Int ) -> Int{ 3; }
14func fun( _ x : Int, _ y : Int ) -> Int{ x + y; }
15func fun( _ x : String ) -> String{ "abc"; }
16print( fun( 3, 4 ) );
17// print( fun( 3.5 ) ); // no Double -> Int
18//print( fun( r3 ) ); // no, Double -> Int
19
20// overloading on parameter name
21func foo( x : Int ) -> Int{ 3; }
22func foo( y : Int ) -> Int{ 3; }
23print( foo( x : 3 ) );
24print( foo( y : 3 ) );
25
26// overloading on generics
27func bar<T>( _ a : T ) { print( "bar1", a ); }
28func bar<T>( _ a : T, _ b : T ) { print( "bar2", a, b ); }
29func bar<T,U>( _ a : T, _ b :  U) { print( "bar3", a, b ); }
30bar( 3 );
31bar( 3.5 );
32bar( 2, 2 );
33bar( 2, 2.5 );
34
35// Local Variables: //
36// compile-command: "swift test.swift" //
37// End: //
Note: See TracBrowser for help on using the repository browser.