I edited the question after David Hanak's answer (thanks by the way!). It helped with the syntax, but it seems that I did not use the correct function to start with.
Basically, I want the compiler to ignore several definitions of a particular label and just use the first one. To do this, I thought I would just do something like this:
\ makeatletter
\ newcommand {\ mylabel} [1] {
\ @ifundefined {# 1} {\ label {# 1}} {X}
}
\ makeatother
This does not work, because the first option is always selected (it does not matter if the label is defined or not). I think that \ @ifundefined (and the proposed \ ifundefined) only works for commands, not shortcuts, but I know little about LaTeX. Any help with this would be great! Thanks!
Significantly late update: I noted David Hanak's answer as the correct answer to my question, but this is not a complete solution, although it really helped me. The problem is that I think, but I'm not an expert, that even if David's code checks to see if the label is defined, it only works when the label was defined in the previous run (i.e., in the .aux file). If two \ mylabels with the same name are defined in the same run, the second will be defined. In addition, even if you manage to get around this, it will force LaTeX to use the first shortcut that you defined in chronological order, and not necessarily the first in the text. Anyway, below is my quick and dirty decision. It takes advantage of the fact that counters are indeed detected immediately.
\ newcommand {\ mylabel} [1] {%
\ @ifundefined { c @ # 1} {%
\newcounter{#1}%
\setcounter{#1}{0}%
}{}%
\ifthenelse{\value{#1} > 0}{}{%
\label{#1}%
\addtocounter{#1}{1}%
}%
}
, 0, , , , .
, "ifthen", .