0
$\begingroup$

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"?

$\endgroup$
5
  • $\begingroup$ For a start, look up DownValues in the docs. $\endgroup$
    – Michael E2
    Commented Apr 17, 2015 at 1:44
  • $\begingroup$ @MichaelE2 Thanks for your advice! $\endgroup$ Commented Apr 17, 2015 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
    Commented Apr 17, 2015 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$ Commented Apr 17, 2015 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$ Commented Apr 17, 2015 at 15:21

1 Answer 1

0
$\begingroup$

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.

DownValues[f]

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

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