Use recursion instead of loop for compiling lambda