Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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

share|improve this question

marked as duplicate by Leonid Shifrin, Yves Klett, Mr.Wizard Dec 4 '12 at 11:42

This question was marked as an exact duplicate of an existing question.

@LeonidShifrin well, there are the much better answers! – Yves Klett Dec 4 '12 at 11:30
@YvesKlett At the time that one was asked, we had a lot of energy since we were only out there for a week :) – Leonid Shifrin Dec 4 '12 at 11:31
@LeonidShifrin question on best practice: since my answer is now quite redundant and I am voting to close, should I delete the answer? – Yves Klett Dec 4 '12 at 11:36
@YvesKlett Since the question is likely going to be closed,I think that does not matter much. – Leonid Shifrin Dec 4 '12 at 11:37
@LeonidShifrin True that. Googling with added to the search terms is often better. – Sjoerd C. de Vries Dec 4 '12 at 12:52

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.

share|improve this answer

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