lua-users home
lua-l archive

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

> On Nov 6, 2018, at 9:29 PM, Luke <> wrote:
> I believe that, because the definition does not begin with function, square is an anonymous function; it returns a value and is defined in an expression. So, I start with the table { 1, 5, 9 }. This is the argument to the square function. I'm guessing that the map function is called by square. But how / why does map get the table, when map only has one parameter, a function, and the table is not assigned to a variable? And how / why does map return a table value, as it seems to want to return a function?

Think of map as a function maker.
After making the function, the job of map is done.
So, map never see the list {1, 5, 9}

square stored what map function maker created.
square is now a function, that map x to x*x

square( {1,5,9} ) ==> {1,25,81}