lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Dec 16, 2010 at 9:16 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> In that case, one can borrow a Python word and use 'range(3,6)' for
> {3,4,5,6}.  How about assigning to an array slice?

Overriding assignment is something we do lack, although it doesn't
feel like a big loss. Python is the Fortran of dynamic languages; if a
feature felt like a good idea, then it would go directly into the
language. And allowing redefinition of something fundamental like
assignment leads to that common anxiety when reading C++ code; what
_exactly_ happens in this (apparently) simple statement?

Something like ls:assign_slice(1,2,{10,20,30}) is explicit and
straightforward [1]

OK, theoretical objections aside, something like this could work:

ls[range(3,6)] = {1}

with __newindex trained to do slice assignment if the key is a list-like table.

steve d.

[1] http://github.com/stevedonovan/Penlight/blob/master/lua/pl/list.lua