il linguaggio Lua: settima parte
segue dalla sesta parte Iteratori e lua funzionale Cos’è un iteratore? Informaticamente parlando, è un costrutto che ci permette di scorrere strutture dati come liste, array, elenchi. In pratica, dato un elemento della struttura il compito dell’iteratore è farci avere il prossimo su cui operare. Non ci stupirà apprendere che in Lua gli iteratori sono funzioni. Vediamo un semplice esempio: function reverse_iter(t) local i=#t+1 return function() i=i-1 if i>=0 then return t[i] end end end...