seqlua

changeset 55:37c2841c6e8c

Added warning regarding nested/repeated loops to README
author jbe
date Wed Aug 27 00:21:04 2014 +0200 (2014-08-27)
parents 92ce3958aca7
children c3976eacc6ab
files README
line diff
     1.1 --- a/README	Wed Aug 27 00:10:47 2014 +0200
     1.2 +++ b/README	Wed Aug 27 00:21:04 2014 +0200
     1.3 @@ -1,7 +1,7 @@
     1.4  seqlua: Extension for handling sequential data in Lua
     1.5  =====================================================
     1.6  
     1.7 -This package is an extension for the Lua programming language (version 5.2)
     1.8 +This package is an experimental extension for the Lua 5.2 programming language
     1.9  which:
    1.10  
    1.11  * allows ``ipairs(seq)`` to accept either tables or functions (i.e function
    1.12 @@ -101,11 +101,23 @@
    1.13  macros to iterate over values in the same manner as a generic loop statement
    1.14  with ``ipairs`` would do.
    1.15  
    1.16 -Note that this extension doesn't aim to supersede Lua's concept of iterator
    1.17 -functions. While metamethods (see section "Respected metamethods" below) may be
    1.18 -used to customize iteration behavior on values, this extension isn't thought to
    1.19 -replace the common practice to use function closures as iterators. Consider the
    1.20 -following example:
    1.21 +Note that in case of repeated or nested loops, using function iterators may not
    1.22 +be feasible:
    1.23 +
    1.24 +    function print_list_twice(seq)
    1.25 +      for i = 1, 2 do
    1.26 +        for i, v in ipairs(seq) do
    1.27 +          print(v)
    1.28 +        end
    1.29 +      end
    1.30 +    end
    1.31 +    print_list_twice(io.stdin:lines())  -- won't work as expected
    1.32 +
    1.33 +Also note that this extension doesn't aim to supersede Lua's concept of
    1.34 +iterator functions. While metamethods (see section "Respected metamethods"
    1.35 +below) may be used to customize iteration behavior on values, this extension
    1.36 +isn't thought to replace the common practice to use function closures as
    1.37 +iterators. Consider the following example:
    1.38  
    1.39      local result = sql_query("SELECT * FROM actor ORDER BY birthdate")
    1.40      write_lines(result:get_column_entries("name"))

Impressum / About Us