2

Possible Duplicate:
Functions vs. patterns

I thought about describing the context in which I faced this problem, but I figured it is general enough and clear enough to pose it as it is.

What is the difference between the two following definitions:

f[x_]:=Sin[x]
g=Sin[#]&

Under what circumstances will the two behave differently? Is any of them preferable as a general practice?

yohbs
  • 7,046
  • 3
  • 29
  • 60

1 Answers1

1

Very short answer on one relevant difference (probably much better ones will appear):

A pure function like g will be faster performance-wise, because it gets rid of all the overhead (e.g. pattern matching) involved in the definition of f.

Yves Klett
  • 15,383
  • 5
  • 57
  • 124