No. Usually when people use "pure" they mean no side effects. They may include other characteristics as well. "Anonymous" means, well, anonymous. That is, an anonymous function is one that is created "on the fly" rather than being retrieved from some variable in the environment.
This expression is an anonymous function:
Function[x, x^2]
That expression in isolation is pretty useless. Once it's evaluated, it's effectively gone (you can reference execution history with %, so that's not strictly speaking true, but practically speaking it's gone). In the following, we're putting an anonymous function to use (presumably we don't expect to use it again later, so we didn't bother giving it a name):
Function[x, x^2] /@ Range[3]
If we did wan't to use it again, we might name it.
MySquare = Function[x, x^2]
Now we can use MySquare and know we're using the exact same function each time. Of course, another functionally equivalent way is this:
MySquare2[x_] := x^2
Side note, the explicit naming of the arguments has nothing to do with a function being anonymous. The following expressions are indeed anonymous, but it's not the absence of "x" that makes them so.
Function[#^2]
#^2&
The following function is not pure:
MySquare3[x_] := (countUsages += 1; x^2)
Incrementing countUsages
is a side effect. The following example demonstrates this:
countUsages = 0;
MySquare3 /@ Range[3];
countUsages
(* 3*)
Without inspecting the definition of MySquare3
, you wouldn't expect countUsages
to change. You can also do this with an anonymous function:
countUsages = 0;
Function[countUsages += 1; #^2] /@ Range[3];
countUsages
(* 3 *)
I should add that, yes, I'm aware the Mathematica documentation often uses "pure" and "anonymous" interchangeably. I find this very strange. The way I justify it to myself is that an expression like MySquare2[x_] := x^2
is actually an assignment of DownValues via SetDelayed, and even though we colloquially say we're defining the MySquare2
"function", we're really defining replacement rules. On the other hand, Function[#^2]
is "self-contained", that is, we don't need to look up replacement rules to figure out how to apply it. I think this "stand alone" quality is what the Mathematica documentation is trying to indicate with "pure". I'm not even really speculating, though, as much as I'm grasping at straws to justify this confusing jargon. I'm not even sure I think that is any different than "anonymous".