Currently I am studying Mathematica programming, and when I study pattern matching and replacement, I find it is quite similar to functions. So can we say "all functions in Mathematica are some kind of pattern-matching-and-replacement procedures"?

  • $\begingroup$ For a start, look up DownValues in the docs. $\endgroup$ – Michael E2 Apr 17 '15 at 1:44
  • $\begingroup$ @MichaelE2 Thanks for your advice! $\endgroup$ – username123 Apr 17 '15 at 1:49
  • $\begingroup$ Here are a couple of answers that (at some point) address your question: mathematica.stackexchange.com/questions/3394/…, mathematica.stackexchange.com/questions/24988/…. There are probably others. The point certainly has arisen several times, though I don't know if anyone has asked it straight out like this. See also: mathematica.stackexchange.com/questions/96/… $\endgroup$ – Michael E2 Apr 17 '15 at 1:55
  • $\begingroup$ One notable example where this is not the case are pure functions. But, unless I am forgetting something, it seems to indeed be the only one. $\endgroup$ – Leonid Shifrin Apr 17 '15 at 3:33
  • $\begingroup$ Actually, I also forgot compiled functions, as the posted answer reminded me (but compiled functions are relatively rarely created at runtime, unlike pure functions). $\endgroup$ – Leonid Shifrin Apr 17 '15 at 15:21

I wouldn't say all functions. For example, consider

f = Compile[{{x, _Real}}, x*x]

There aren't any replacement rules for f in this case.


(* {} *)
  • 1
    $\begingroup$ Try OwnValues[f]. $\endgroup$ – Michael E2 Apr 17 '15 at 10:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.