|
Test1 – this example demonstrates how to pass functions to other
functions
using
System; class Test1
{ int fun1( (int) => int
fun2 ) { return fun2( 2 ); } int fun3( int x ) { return x * x; } public static void Test1 t = new Test1();
Console.WriteLine( t.fun1( t.fun3 ) ); } } |
|
Test2 – this example demonstrates how to pass asynchronous functions
to other functions using
System; using
System.Threading; class
Test2 { void fun1( (int) => async
fun2 ) { fun2( 2 ); } async fun3( int x ) {
Thread.Sleep( 1000 ); Console.WriteLine(
x * x ); } public static void Test2 t = new Test2(); t.fun1( t.fun3
);
Console.WriteLine( “fun1 is running… (Press Enter)” );
Console.ReadLine(); } } |
|
Test3 – this example demonstrates how to use static asynchronous
functions using
System; using
System.Threading; class
Test3 { static async
fun1( int x ) {
Thread.Sleep( 1000 ); Console.WriteLine(
x * x ); } public static void Test3.fun1( 2
);
Console.WriteLine( “fun1 is running… (Press Enter)” );
Console.ReadLine(); } } |
|
Test4 – this example demonstrates how to pass function to another one
function. Passed function returns void type and accepts one integer parameter using
System; class Test4
{ void fun1( (int) => void
fun2 ) { fun2( 2 ); } void fun3( int x ) { Console.WriteLine(
x * x ); } public static void Test4 t = new Test4(); t.fun1(
t.fun3 ); } } |
|
Test5 – this example demonstrates how to pass function to another one
function. The function that is passed doesn’t expect parameters and returns
void using
System; class Test5
{ void fun1( () => void fun2 ) { fun2(); } void fun3() { Console.WriteLine(
2 * 2 ); } public static void Test5 t = new Test5(); t.fun1(
t.fun3 ); } } |
|
Test6 – this example demonstrates how to use static movable methods using
System; class Test6
{ static movable fun1(
int x ) {
Console.WriteLine( “Hello world! ” + x ); } public static void Test6.fun1(
2 ); } } |
|
Test7 – this example demonstrates how to use non-static movable
methods using
System; class Test7
{ movable fun1( int x ) {
Console.WriteLine( “Hello world! ” + x ); } public static void Test7 t = new Test7(); t.fun1( 2 ); } } |
|
Test8 – this example demonstrates how to call proxy functions from
movable methods. Proxy function doesn’t expect parameters and returns some
inv value
using
System; class Test8
{ movable fun1( (int) => int fun ) {
Console.WriteLine( fun( 2 ) ); } int fun2( int x ) { return x * x; } public static void Test8 t = new Test8(); t.fun1( t.fun2
); } } |
|
Test9 – this example demonstrates how to call proxy functions from
static movable methods. Proxy function doesn’t expect parameters and returns
void using
System; class Test9
{ static movable fun1(
() => void fun ) { fun(); } static void fun2()
{
Console.WriteLine( “fun2 has been called!” ); } public static void Test9.fun1( Test9.fun2
); } } |
|
Test10 – this example demonstrates how to use local function pointers using
System; class Test10
{ static movable
fun1( () => void fun ) { () => proxy void myfun = fun; myfun(); } static void fun2()
{
Console.WriteLine( “fun2 has been called!” ); } public static void Test10.fun1(
Test10.fun2 ); } } |
|
Test11 – this example demonstrates how to declare function pointers in
the class structure using
System; class Test11
{ static () => proxy void myfun; static movable fun1(
() => void fun ) { Test11.myfun
= fun;
Test11.myfun(); } static void fun2() {
Console.WriteLine( “fun2 has been called!” ); } public static void Test11.fun1(
Test11.fun2 ); } } |
|
Test12 - this example demonstrates how to use asynchronous proxy
functions using
System; class
Test12 { static movable
fun1( () => async fun ) { fun();
Console.WriteLine( “fun1 executing” ); } static async
fun2() {
Console.WriteLine( “fun2 executing” ); } public static void Test12.fun1(
Test12.fun2 ); } } |
|
Test13 – this example demonstrates how to use joins using
System; class Test13
{ int Receive() & async Send( int x ) { return x * x; } public static void Test13 t = new Test13(); t.Send( 2 );
Console.WriteLine( t.Receive() ); } } |
|
Test14 – this example demonstrates how to use totally asynchronous joins using
System; class Test14
{ async a() & async b() {
Console.WriteLine( “async a() & async b()” ); } public static void Test14 t = new Test14(); t.b(); t.a();
Console.WriteLine( “Press Enter” );
Console.ReadLine(); } } |
|
Test15 – this example demonstrates how to use the same synchronous
method in two joins using
System; class Test15
{ void a() & async b() {
Console.WriteLine( “void a() & async b()” ); } void a() & async c() {
Console.WriteLine( “void a() & async c()” ); } public static void Test15 t = new Test15(); t.b(); t.a(); t.c(); t.a(); } } |
|
Test16 – this example demonstrates how to use one asynchronous method
in two joins using
System; class Test16
{ void a() & async b() {
Console.WriteLine( “void a() & async b()” ); } void c() & async b() {
Console.WriteLine( “void c() & async b()” ); } public static void Test16 t = new Test16(); t.b(); t.a(); t.b(); t.c(); } } |
|
Test17 – this example demonstrates how to use static joins using
System; class Test17
{ static int Receive() & static async Send(
int x ) { return x * x; } public static void Test17.Send(
2 );
Console.WriteLine( Test17.Receive() ); } } |
|
Test18 – this example demonstrates how to use both static and
non-static joins in one class using
System; class Test18
{ static int Receive() & static async
Send( int x ) { return x * x; } void a() & async b() { Console.WriteLine(
“void a() & async b()” ); } public static void Test18.Send(
2 );
Console.WriteLine( Test18.Receive() ); Test18 t = new Test18(); t.b(); t.a(); } } |
|
Test19 – this example shows the difference between passing async
method to movable and local method – this test is not working in current
implementation using
System; class
Test19 { static movable fun1( () => async fun
) {
Console.WriteLine( “movable fun1()” ); fun(); } static void
fun1( () => async fun ) {
Console.WriteLine( “fun1()” ); fun(); } static async fun2()
{
Console.WriteLine( “fun2()” ); } public static void Test19.fun1(
proxy Test19.fun2 ); Test19.fun1(
Test19.fun2 ); } } |
|
Test20 – this example demonstrates how to convert async methods to
proxy async methods using
System; class
Test20 { static movable fun1( () => async fun
) {
Console.WriteLine( “movable fun1()” ); fun(); } static async fun2() {
Console.WriteLine( “fun2()” ); } public static void () => async fun = Test20.fun2; Test20.fun1(
fun ); } } |
|
Test21 – this example demonstrates how to convert sync methods that
returns void to proxy sync methods that returns void using
System; class
Test21 { static movable
fun1( () => void fun ) {
Console.WriteLine( “movable fun1()” ); fun(); } static void fun2()
{
Console.WriteLine( “fun2()” ); } public static void () => void fun = Test21.fun2; Test21.fun1(
fun ); Console.WriteLine(
“Done!” ); } } |
|
Test22 - this
example demonstrates how to convert non-void sync methods to proxy non-void
sync methods using
System; class
Test22 { static movable fun1( (int) => int fun ) {
Console.WriteLine( “movable fun1()” ); Console.WriteLine(
fun( 2 ) ); } static int fun2( int x ) {
Console.WriteLine( “fun2()” ); return x * x; } public static void (int) => int fun = Test22.fun2; Test22.fun1(
fun );
Console.WriteLine( “Done!” ); } } |