lua-users home
lua-l archive

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

On Thu, May 14, 2009 at 5:56 AM, David Manura <> wrote:
> I don't really like the complicating DWIM stuff in List:map (i.e.
> is_type(arg1,List)):
>  function List:map (fun,arg1,...)
>    local res
>    if is_type(arg1,List) then
>        res = map2(fun,self,arg1,...)
>    else
>        res = imap(fun,self,arg1,...)
>    end
>    return setmetatable(res,List)
>  end
> e.g. what if someone really wanted to pass a list as arg1 and have it
> operated with imap?

Yes, you are right, and to be consistent this is really two separate
functions, map and map2

To be really safe, we need tablex.imap2, because map2 does iterate
over the hash part of the table as well, leading to odd effects.

steve d.