6.82 Correct way to define function for Integrate use

Watch out when defining a function such as this:

f[x_] := Integrate[x - t, {t, 0, x}]
 

The problem is this:

In[45]:= f[t] 
Out[45]= 0
 

This is becuase the replacement of "x" by "t" changed the integrand to zero.

The correct way is to always use Module symbols for everything inside the function, like this

f[x_] := Module[{t}, Integrate[x - t, {t, 0, x}]]
 

Now it gives the correct answer regardless of the symbol used as argument

In[46]:= f[t] 
Out[46]= t^2/2 
 
In[47]:= f[x] 
Out[47]= x^2/2