For which conditions on countable sets does continuity implies uniform continuity This is an exercise from Thomson and Bruckner's "Elementary Real Analysis" (Exercise 5.6.5 page 239):

Let $X=\{x_1,x_2,\dots,x_n,\dots\}$. What property must $X$ have so that every function continuous on $X$ is uniformly continuous on $X$?

The set $X$ is a subset of $\mathbb {R}$. I worked on the $\varepsilon-\delta$ definitions of limits and uniform continuity, but I coudln't link between them. Could you please help me?
Edit: I removed the part My attempt because my result was wrong.
 A: A subset $X\subseteq \mathbb R$ has the property that every continuous $f:X\to\mathbb R$ is also uniformly continuous if and only if

  
*
  
*$X$ is closed.
  
*There exists some $M>0$ such that every limit point $p$ of $X$ follows $|p| < M$.
  
*$X\setminus[-M, M]$ is uniformly discrete. That is, there exists some $\delta > 0$ such that for every $x,y\in X\setminus[-M,M]$ with $x\ne y$ it follows
  $$ |x-y| \ge \delta. $$
  

If part:
Since $X\cap[-M,M]$ is compact, any continuous function restricted onto $X\cap[-M,M]$ is uniformly continuous. Further, since $X\setminus[-M,M]$ is uniformly discrete, any function restricted onto $X\setminus[-M,M]$ is uniformly continuous.
Only if part:


*

*If $f$ is uniformly continuous on $X$, then we may extend $f$ to an uniformly continuous function on the closure of $X$. So, $\lim_{x\to x^*} f(x)$ need to exists for any closure point $x^*$ of $X$. Assume the contrary that $x^*$ is a limit point of $X$ not in $X$. Then, the function $f(x) = (x-x^*)^{-1}$ is continuous on $X$ but has no limit at $x^*$.

*Assume the contrary that the limit points are unbounded, without the loss of generality unbounded from above. 
Then, there exists a strictly increasing and unbounded sequence of limit points $p_0 < p_1 < \dotsb$. 
Now, for $n\ge 1$ let 
$$ \delta_n = \min\left\{\frac1n, \frac{p_{n} - p_{n-1}}{2}, \frac{p_{n+1} - p_{n}}{2} \right\}. $$
Since $p_n$ is a limit point, there exists some $x_n\in X\setminus\{p_n\}$ with $\delta'_n := |x_n - p_n| < \delta_n$.
Now, define the function $f:X\to\mathbb R$ by
$$ f(x) = \begin{cases} 1, & |x - p_n| < \delta'_n \text{ for some } n\ge 1, \\
0, & \text{otherwise}.
\end{cases}
$$ 
Then, $f$ is continuous, but $|f(x_n) - f(p_n)| = 1$ and $|x_n - p_n| < \frac1n \to 0$. That is, $f$ is not uniformly continuous.

*Notice that $X\setminus[-M, M]$ is discrete. Assume that again the contrary that $X\setminus[-M, M]$ is not uniformly discrete. 
Let $X_1 = X\setminus[-M, M]$.
Let $x_1,y_1\in X_1$ with $x_1\ne y_1$ and $|x_1 - y_1| < 1$.
Let $X_2 = X_1\setminus\{x_1, y_2\}$.
Since $X_1$ is discrete, $X_2$ is discrete and therefore also closed. 
Thus, $x_1$ and $y_1$ has positive distance to $X_2$, and $X_2$ is not uniformly discrete (otherwise $X_1$ would be also uniformly discrete, a contradiction).
So, we can iteratively define $x_n,y_n\in X_n$ with $x_n\ne y_n$ and $|x_n-y_n| < \frac1n$ and $X_{n+1} = X_n\setminus\{x_n, y_n\}$.
Define the function $f:X\to \mathbb R$ by
$$ f(x) = \begin{cases} 1, & x = x_n \text{ for some } n, \\
0, & \text{otherwise}.
\end{cases}
$$ 
Then, $f$ is continuous. But $f(x_n) - f(y_n) = 1$ and $|x_n - y_n| < \frac1n \to 0$. Again, $f$ is not uniformly continuous.
Notes: Since the proof of 2. and 3. are similar, it might be possible to combine conditions 2 and 3 to something more nice looking.
A: Partial results:


*

*$X$ must be closed in $\mathbb {R}.$ If not, there is a sequence $x_n$ in $X$ with $x_n\to a, a\not \in X.$ Then the function $f(x) = 1/|x-a|$ is continuous on $X.$ The $x_n$ are getting close to one another, yet $f(x_n)$ is unbounded. Hence $f$ is not uniformly continuous on $X.$

*Note that every function on $\mathbb N$ is uniformly continuous on $\mathbb N.$ So $X$ need not be bounded.
