Halmos set definition of projection onto the first coordinate, notation confusion.
Solution 1:
When you define the set $A$ you don't "have" it yet (i.e. you haven't shown $A$ exists), so you cannot use comprehension over $A$ as you do. That's circular.
But Halmos works more naively and starts out from $R$ directly:
$A=\{a\mid \exists b : (a,b) \in R\}$, leaving it undetermined what sets $a$ and $b$ come from..
If you want to be fully formal (axiomatic), you can find a set of which $A$ is a subset (hint: union axiom and recall that $(a,b) = \{\{a\}, \{a,b\}\}$ if we follow Kuratowski, I don't recall if Halmos does this though..) and use comprehension from that. Or use axiom of replacement, maybe.