A fresh Mathematica session with
$Version
"11.0.1 for Microsoft Windows (64-bit) (September 20, 2016)"
produces the following results.
Names["x*"]
(* {} *)
Table[Unique["x"], 4]
(* {x3, x4, x5, x6} *)
Names["x*"]
(* {"x3", "x4", "x5", "x6"} *)
The first thing one notices is that, according to the Mathematica documentation, the results of Unique should be
(* {x1, x2, x3, x4} *)
In fact, even executing (in a fresh session) the first basic example in the Unique documentation changes Out[1] from x1 to x3. To continue,
Remove["x*"]
Names["x*"]
(* {} *)
apparently removes all traces of the x symbols, but it does not reset the Unique counter
Table[Unique["x"], 4]
(* {x7, x8, x9, x10} *)
The counter even persists across different families of symbols.
Table[Unique["z"], 4]
(* {z11, z12, z13, z14} *)
It also persists across contexts, but not across kernels.
How can this Unique counter (which is not $ModuleNumber) be reset? And, is this a bug?
Uniqueis using the same$ModuleNumbercounter asModule. – Leonid Shifrin Oct 10 '16 at 16:04Unique["string"]. If you want something you can rely on, try this: http://mathematica.stackexchange.com/a/103751/5478 – Kuba Oct 10 '16 at 17:55Uniqueor its documentation has a problem, which should be fixed. – bbgodfrey Oct 10 '16 at 18:00Unique["x"]uses the first unused symbol of the formxnnn". One would assume the "first" one in a new kernel is the one wherennnis the first positive integer. – Feyre Oct 10 '16 at 18:23$ModuleNumbershould be1for a fresh kernel too. Both cases probably start with1but are used in autoloaded packages or something, why not really. Maybe built in packages should not interfere but there are more problems with documentation that are higher on my concerns' list :) – Kuba Oct 10 '16 at 19:56$ModuleNumbersupposed to change its value? It does in strange ways and I see nothing in the docs to say it should. – george2079 Oct 11 '16 at 20:49