Function[{u}, g[u]]
Function[u, g[u]]
The documentation lists both variants without specifying the difference. Does the behavior differ in some circumstances?
Function[{u}, g[u]]
Function[u, g[u]]
The documentation lists both variants without specifying the difference. Does the behavior differ in some circumstances?
There is no functional difference between Function[{u}, g[u]] and
Function[u, g[u]]. The following difference in speed is small but consistent on my machine (MacBook Pro):
foo = Range[5*10^6];
foo[[1]] = 1.;
Function[x, x] /@ foo; // RepeatedTiming
Function[{x}, x] /@ foo; // RepeatedTiming
(*
{2.4, Null}
{2.0, Null}
*)
It's a small difference compared to the execution time of more complicated function bodies.
Note on the example:
The line foo[[1]] = 1. unpacks the array foo and prevents it from being packed. This in turn prevents the functions from being auto-compiled by Map (/@). If the functions are compiled, then all differences between them are erased.