[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Apologies for bad formatting: lecture slides etc.
- From: Albert Chan <albertmcchan@...>
- Date: Tue, 6 Nov 2018 22:24:19 -0500
On Nov 6, 2018, at 10:05 PM, Luke <lemmett81@gmail.com> 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