# Basic Question on function of $n$ when it shift to $n-1$ [duplicate]

This question is basic, but I do not know what is wrong.

Clear[a0,a]
a0=n;
a[n_]:=a0


But when I evaluate a[n-1] the output gives n which is same as a[n], it should be n-1 but why is it n? Could someone spot the error?

• Can't you just do a[n_] := n?? The reason this happens is that there is nothing that matches the pattern n_ on the right hand side of the definition og a[n_]. So no matter what you give as input, it will match n_, but then this won't be used anywhere, Mathematica will just return a0, which contains the symbol n, not the thing that matched the patter n_. Commented Jun 14, 2016 at 15:31
• Possible duplicates?: (11461), (69590) Commented Jun 14, 2016 at 15:46
• @MariusLadegårdMeyer, I can not do that. This is just a simple example of my problem bigger code which run that way. But thanks for trying to help, I appreciate it. Thanks :) Commented Jun 15, 2016 at 3:33
• @Mr.Wizard Hi Thanks for giving the links. I tried one of the suggestion given in the link and it works. Thanks Mr :) Commented Jun 15, 2016 at 3:34
• I am glad your problem was solved. If in the future a question of yours is closed as a duplicate but you find that solutions given do not work, or your problem was actually different, please know that you can edit your question to explain this and it will be added to the Review Queue for reopening. Commented Jun 15, 2016 at 6:39