0

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
username123
  • 257
  • 1
  • 6
  • For a start, look up DownValues in the docs. – Michael E2 Apr 17 '15 at 01:44
  • @MichaelE2 Thanks for your advice! – username123 Apr 17 '15 at 01:49
  • Here are a couple of answers that (at some point) address your question: http://mathematica.stackexchange.com/questions/3394/arguments-to-if-are-not-evaluated/3398#3398, http://mathematica.stackexchange.com/questions/24988/can-one-identify-the-design-patterns-of-mathematica/25150#25150. 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: http://mathematica.stackexchange.com/questions/96/what-is-the-distinction-between-downvalues-upvalues-subvalues-and-ownvalues – Michael E2 Apr 17 '15 at 01:55
  • 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. – Leonid Shifrin Apr 17 '15 at 03:33
  • Actually, I also forgot compiled functions, as the posted answer reminded me (but compiled functions are relatively rarely created at runtime, unlike pure functions). – Leonid Shifrin Apr 17 '15 at 15:21

1 Answers1

0

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]

(* {} *)
rhennigan
  • 1,783
  • 10
  • 19