|
> 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)On Wed, 7 Nov 2018 at 02:59, Albert Chan <albertmcchan@yahoo.com> wrote:
> On Nov 6, 2018, at 9:29 PM, Luke <lemmett81@gmail.com> 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}