init
	Test.init( ref args )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/01", test1 )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/02", test2 )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/03", test3 )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/04", test4 )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/05", test5 )
	Test.add_func( "/FunctionalTests/Genie/Functions/ReturnValues/AnonymousFunctions/06", test6 )
	Test.run()

// Simple function that returns an anonymous function
delegate Anonymous1()
def test1()
	result:Anonymous1 = test1_function()
	result()

def test1_function():Anonymous1
	return def()
		assert( true )

// Function that returns an anonymous function with a parameter
delegate Anonymous2( a:int )
def test2()
	x:Anonymous2 = test2_function()
	x( 1 )

def test2_function():Anonymous2
	return def( b )
		assert( b == 1 )

// Function that returns an anonymous function with a parameter and return value
delegate Anonymous3( a:int ):int
def test3()
	x:Anonymous3 = test3_function()
	result:int = x( 1 )
	assert( result == 2 )

def test3_function():Anonymous3
	return def ( b )
		return b + 1

// Function that returns an anonymous function with multiple parameters and a return value
delegate Anonymous4( i:int, j:int, k:int ):int
def test4()
	x:Anonymous4 = test4_function()
	var result = x( 1, 2, 3 )
	assert( result == 6 )

def test4_function():Anonymous4
	return def( a, b, c )
		return a + b + c

// Function that returns an anonymous function with a variable in the enclosing context (a closure)
delegate Anonymous5( i:int ):int
def test5()
	x:Anonymous5 = test5_function( 1 )
	result:int = x( 2 )
	assert( result == 6 )

def test5_function( a:int ):Anonymous5
	return def( b )
		return a + b + 3

// Example of currying
delegate Anonymous6( i:int ):int
def test6()
	result:int = test6_function( 1 )( 2 )
	assert( result == 3 )

def test6_function( a:int ):Anonymous6
	return def( b )
		return a + b

/* Produces C compilation error 
// More complex example of currying
delegate Anonymous7_1( i:int ):Anonymous7_2
delegate Anonymous7_2( i:int ):int
def test7()
	result:int = test7_function( 1 )( 2 )( 3 )
	assert( result == 6 )

def test7_function( a:int ):Anonymous7_1
	return def( b )
		b = b + a
		return def( c )
			c = c + b
			return c
*/
