# HG changeset patch # User jbe # Date 1408930954 -7200 # Node ID 54647a56a47ab630293d34aac7c2f63137cc5db0 # Parent 21230b38d85843e7df0a7de07d50b341fef80251 Fixed third example of "write_lines" in README diff -r 21230b38d858 -r 54647a56a47a README --- a/README Mon Aug 25 03:22:46 2014 +0200 +++ b/README Mon Aug 25 03:42:34 2014 +0200 @@ -63,20 +63,25 @@ If one wanted to create a function that accepts either a sequence in form of a table or an iterator function, then one might need to write: - function write_lines(lines) - local iter1, iter2, iter3 - if type(lines) == "function" then - iter1 = lines - else - iter1, iter2, iter3 = ipairs(lines) - end - for i, line in iter1, iter2, iter3 do + do + local function write_line(line) io.stdout:write(line) io.stdout:write("\n") end + function write_lines(lines) + if type(lines) == "function" then + for line in lines do + write_line(line) + end + else + for i, line in ipairs(lines) do + write_line(line) + end + end + end end -Obviously, this isn't something we want to write in every function that accepts +Obviously, this isn't something we want to do in every function that accepts sequential data. Therefore, we usually decide for one of the two first forms and therefore disallow the other possible representation of sequential data to be passed to the function.