Problem:
Find examples of functions $f$ and $g$ defined on $\mathbb{R}$ with $\lim\limits_{x\to a}f(x) = L$, $\lim\limits_{y\to L}g(y) = M$, and $\lim\limits_{x\to a} g(f(x))\neq M$.
I have tried various combinations like $f(x) = x$ and $g(y) = y^2$, $f(x) = b$ and $g(y) = y^2$, and so on. I have even tried with some trigonometric functions with no luck. I am wondering what characteristic am I trying to "break" so that the conditions do not hold. Also, since $f$ and $g$ have to be defined on $\mathbb{R}$, does that mean that something like $\frac{1}{x}=f(x)$ is not a valid example since it is not defined at $x=0$?
Thanks for your help.
The answer probably depends on the definition of limit. I will use the following definition (from Stewart's Calculus):
$0<|x-a|<\delta$ means that the value of $f$ at $a$ does not matter. $f$ could even not be defined at $a$ at all. In some books the condition is $0<|x−a|<δ$ is changed to $|x-a|<\delta$. In that case, you should have a look to @msm's answer.
If you are using the above definition, then consider $f(x)=\left\{\begin{array}{ll} 1, & x\neq 0 \\ 0, & x=0 \end{array} \right.$ and $g(x)=\left\{\begin{array}{ll} 0, & x\neq 1 \\ 1, & x=1 \end{array} \right.$. Then $\lim_{x\to 0}f(x)=1$ and $\lim_{x\to 1}g(x)=0$. but $\lim_{x\to 0} g\circ f(x)=1\neq 0$.
Note that, if $f$ is continuous at $a$, then $\ell=f(a)$ and
is equivalent to
since, $|x-a|=0$ means that $x=a$ and in that case, $|f(x)-\ell|=0$.