lua-users home
lua-l archive

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

On Nov 6, 2018, at 10:05 PM, Luke <> wrote:

> > 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} 
> That makes sense. Why don't we use function to define square?
> function square = map(function (x) return x * x end)

Because the function is *already* defined from map.
All we need is store this function object into a variable, name "square"
(besides, above is not valid lua code)

You can also think like this:

function add1(x) return x+1 end

is same as:

add1 = function(x) return x+1 end