MCSN-project2014 / APproject

Project for the MCSN Advanced Programming Module A.Y. 2014/2015
http://mcsn-project2014.github.io/APproject/
MIT License
4 stars 0 forks source link

Anonymous functions #37

Closed teto1992 closed 9 years ago

teto1992 commented 9 years ago

There is a - hopefully minor - issue with the assignment of the result of an anonymous function to a variable. See the code:

/** A test for closures of
anonymous functions
**/ 

fun tick() fun() int{
    var counter int = 0;
    return fun() int{
        counter = counter + 1;
        return counter;
    };
}

fun main(){
    var tick1 fun = tick();
    var tmp int = (tick1());
    while tmp != 10 {
        var x int = readln();
        if tick1() == 5{
            println("halfway through");
        }
        tmp = tick1();
    }
    println("It's over");
}```