# Is there a way to know name clashes in PostScript level between ones used in PSTricks packages and our own definitions?

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}

\begin{pspicture}[showgrid=bottom](4,2)
\pstVerb
{
/a 2 def
/bb 1 def
}%
\rput(!a bb){First Page}
\end{pspicture}

\end{document}


My a silently overrides the PSTricks' definition. I need a way to know this silent substitution. Is there a way to know name clashes in PostScript level between ones used in PSTricks packages and our own definitions?

-

I suppose the correct thing to do is always make your local definitions in a private dictionary to avoid the problem but this postscript addresses the question as asked:

The sequence

 dup where {pop == (already defined) ==} {3 def} ifelse


will define the preceding token to 3 if it is not defined, and leave it untouched and echo a warning if it is defined.

tested with /a defined to be 2 and /b undefined

GS>/a 2 def
GS>/a dup where {pop == (already defined) ==} {3 def} ifelse
/a
GS>a ==
2
GS>/b dup where {pop == (already defined) ==} {3 def} ifelse
GS> b ==
3


a gets left as 2 but b is defined to be 3.

-
Note in the other answer Herbert shows what I noted above is the "correct thing to do" :-) –  David Carlisle Sep 6 '12 at 13:26
\documentclass{article}
\usepackage{pstricks}\SpecialCoor
\begin{document}

\begin{pspicture}[showgrid=bottom](4,2)
\pstVerb
{  userdict begin
/a 2 def
/bb 1 def
end }
\rput(! userdict begin a bb end){First Page}
\end{pspicture}

\end{document}

-
I used this in my project but I accepted David solution because it conforms to the question. –  kiss my armpit Sep 6 '12 at 13:32
Is there a method to avoid repeating userdict begin ... end in each points? –  kiss my armpit Sep 6 '12 at 13:53