I was looking up the definition of the derivative in several books, and what was making me uneasy was the first sentence, generally along the lines of "let $f$ be defined on...". They don't seem to be able to agree on what $f$ should be defined on. Most books say "interval"; one says "open set"; another just says "let $f$ be a real-valued function"; etc. So I decided to do a little investigation.
At the end of the day, we always define the derivative as the limit of a difference quotient (two versions), so we need to look into limits of functions. It turns out that the limit of $f$ at $a$ is only defined for $a \in (\operatorname{dom} f)'$ (we'll denote the set of cluster points of $A$ by $A'$ for convenience), because otherwise, the $0 < |x - a| < \delta$ part of the definition can be made false by choosing $\delta$ small enough to isolate $a$, thereby making the implication vacuously true, which gives non-unique limits, but we don't want that. So at this point, we know that $a$ must be a cluster point of the domain of the difference quotient.
A slight digression: It's easy to show that if $B$ is a finite set, then $A' = (A \cup B)' = (A \setminus B)'$. (That is, "adding" or "subtracting" a finite number of points doesn't affect the "stickiness" of a set.)
Let $A \subseteq \mathbb R$ and let $f: A \to \mathbb R$. For each $a \in A$, we can define a difference quotient function $q_a: A \setminus \{a\} \to \mathbb R$ by $$q_a(x) = \frac{f(x) - f(a)}{x - a}.$$
Now, (in a rather perverted pseudo-self-referential manner), we can define $$f': \{a \in A \cap A': \lim_{x \to a} q_a(x) \in \mathbb R \} \to \mathbb R \qquad \text{by} \qquad f'(a) = \lim_{x \to a} q_a(x).$$
We need $a \in A$ because $f(a)$ is needed to evaluate $q_a$, and we need $a \in A' = (A \setminus \{a\})' = (\operatorname{dom} q_a)'$ for the limit to be defined. So really, derivatives can be defined on sets that are much more general than intervals: we really only need $\operatorname{dom} f \cap (\operatorname{dom} f)' \neq \varnothing$ in order to talk about the derivative of $f$ at some point (of course, the derivative itself need not exist, but at least we can talk about it not existing).
And then I started getting worried... The function $f: \mathbb R \to \mathbb R$, defined by $$f(x) = \begin{cases} x, & x \in \mathbb Q, \\ 0, & x \notin \mathbb Q, \end{cases}$$ has no derivative anywhere. But if we restrict the domain to $\mathbb Q$, then suddenly every point is differentiable with derivative $1$? Now I'm starting to wonder if I made some stupid mistake in the development above, but I can't seem to find it.
So the question is, is the bolded statement above true?