anonymous functions

This commit is contained in:
Steven Degutis
2012-03-16 07:09:05 -05:00
parent c2a8b55d70
commit 0bc49e55a4
2 changed files with 31 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
package go_koans
func testAnonymousFunctions() {
{
i := 1
increment := func() {
i++
}
increment()
assert(i == __int__) // closures function in an obvious way
}
{
i := 1
increment := func(x int) {
x++
}
increment(i)
assert(i == __int__) // although anonymous functions need not always be closures
}
{
double := func(x int) int { return x * 2 }
assert(double(3) == __int__) // they can do anything our hearts desire
}
}

View File

@@ -22,12 +22,12 @@ func TestKoans(t *testing.T) {
//testArrays()
//testSlices()
//testControlFlow()
testEnumeration()
//testEnumeration()
testAnonymousFunctions()
// TODO: ie, gameplan
//testFiles()
//testVariadicFunctions()
//testAnonymousFunctions()
//testInterfaces()
//testMaps()
//testStructs()