That error message would be produced if the variable whose name you passed to rep
did not exist in the calling scope. For example, check this interactive session with tclsh…
% proc rep {name} { upvar $name n puts "nm is $n" } % rep foo can't read "n": no such variable % set foo x x % rep foo nm is x
Going deeper…
The variable foo
is in a funny state after the upvar
if it is unset; it's actually existing (it's referenced in the global namespace's hash table of variables) but has no contents, so tests of whether it exists fail. (A variable is said to exist when it has an entry somewhere — that is, some storage to put its contents in — and it has a value set in that storage; an unset variable can be one that has a NULL
at the C level in that storage. The Tcl language itself does not support NULL
values at all for this reason; they correspond to non-existence.)