Im sitting in the class, reading the PIL book or whatever you call it. And Im having an issue, understanding the Tail Calls, Iterators ans Closures. As I got the point, it's pretty important to understand it perfectly, but because words are pretty hard understandable, I'm asking here to help me out with this.
How did you get the meaning of Iterators, Taill Calls and Closures on your own?
(For all the haters who thinks i read it once - you're wrong)
Have a nice day!
Comments
Closures - variables that hold functions and can be called
in lua it makes less sense, cause
Tail Calls - last functions called in some scope (like outer function)
Likes: tytadas
I suggest Arturs' book https://www.packtpub.com/game-development/gideros-mobile-game-development (available also on google books and maybe on amazon)
It's very well written and explained, and guides you through the steps needed to develop a basic game.
Once you've learned how things work in gideros, it's easy to understand what you need to do and when.
About your question I think that you just need to know what iterators are, why should you care about tail calls and closures? :P
Learn a few things at a time, you can always go deeper later.
Simply put, iterators are functions that allow you to read (and eventually do something on each) entry of a table. ie. for, for... in pairs and for... in ipairs
Another thing is: we're lucky there are no haters here..
[edit - Arturs was faster ]
Likes: tytadas
Likes: tytadas
Closure is a function with it's own table of upvalues. Upvalue is a local variable from enclosing function, neither a parameter of this function, nor global variable:
To better understand it: each function has access to: it's parameters (local variables from this function), it's upvalues (local variables from enclosing functions) and global variables.
Just like classes, closures is another way to create and control objects but instead of class fields, methods and members they rely on functions, upvalues and lexical scoping. Most modern languages have it because in some cases they offer more clean and elegant approach than classes.
Example from the PIL:
Without closures you need either create 3 versions of `function (n1, n2) return grades[n1] > grades[n2] end` (if you want to use different local variables for names and grades) or modify global variables `names` and `grades` each time before using it (easy to make a mistake).
With closures we have clean solution:
Next example:
Likes: talis, totebo, pie, simwhi, tytadas, chuz0, EricCarr
Likes: tytadas