5
$\begingroup$

Example

Unique[x] generates a new symbol, with a name of the form x$nnn.

If so then this is not correct:

Unique[x$]
x$4639

I'd expect double $: x$$4639.


Question:

Is this a bug in Unique, a documentation bug or have I missed something?


Further investigation

It only happens for single $ but I have failed to find any reason why not to use such names.

Unique /@ {x$$, x$, x}
{x$$$4694, x$4695, x$4696}

This has further consequences, some of which I consider bugs but I will stop here as those examples are enough for discussion.

$\endgroup$
  • 3
    $\begingroup$ One good reason not to use such names is that the lexical renaming mechanism used in various places will add the $ character to symbols in an attempt to disambiguate the same symbol appearing in different scopes. It has been suggested that we document this e.g. in Function and this is on someone's to-do list (mine, I guess). $\endgroup$ – Daniel Lichtblau Apr 27 '17 at 15:46
  • $\begingroup$ @DanielLichtblau Didn't you do that already? Function / Properties&Relations / 4th example. $\endgroup$ – Kuba Apr 27 '17 at 21:15
  • 2
    $\begingroup$ Yes, we do document that such rewriting takes place. What I meant it is that there is an open suggestion for Possible Issues, to the effect of "Don't use variables like this because it will interfere with rewriting in ways that are difficult to predict". $\endgroup$ – Daniel Lichtblau Apr 27 '17 at 21:32
  • $\begingroup$ @DanielLichtblau I see. Let me suggest to stress that out in the tutorial linked in the answer and then add a reference in details&options of all relevant functions. Here is another victim of the special treatment for name$ symbols: DynamicModule[{x$ = .5}, {Dynamic[x], Slider@Dynamic[x$]}] $\endgroup$ – Kuba Apr 28 '17 at 8:02
2
$\begingroup$

Symbols in the Wolfram Language

aaaaa   user‐defined symbol
Aaaaa   system‐defined symbol
$Aaaa	global or internal system‐defined symbol
aaaa$  symbol renamed in a scoping construct
aa$nn   unique local symbol generated in a module

According to the forms of symbols, x in Unique[x] shouldn't be aaaa$$.

http://reference.wolfram.com/language/tutorial/BasicObjects.html http://reference.wolfram.com/language/tutorial/LettersAndLetterLikeForms.html

Workaround:

In:

Unique["x$$"]

Out:

x$$6
$\endgroup$
  • $\begingroup$ That list gives a clue but notice that Unique documentation doesn't say that x has to be a 'user-defined symbol' $\endgroup$ – Kuba Apr 27 '17 at 9:01
  • $\begingroup$ @Kuba The name of a symbol must be a sequence of letters, letter‐like forms, and digits, not starting with a digit. $ is a special character. $\endgroup$ – UnchartedWorks Apr 27 '17 at 9:07
  • $\begingroup$ Sorry for being picky, I'm arguing with documentation not with you of course ;) So. "the name of a symbol" not the name of "a user defined symbol", and since "$" is included below it is probably considered a letter-like form. $\endgroup$ – Kuba Apr 27 '17 at 9:11
  • $\begingroup$ $ doesn't belong to Letters and Letter-like Forms in Wolfram Language. reference.wolfram.com/language/tutorial/… $\endgroup$ – UnchartedWorks Apr 27 '17 at 9:55
  • $\begingroup$ Ok, but again, Unique does not say it only work with "user defined symbols". $\endgroup$ – Kuba Apr 27 '17 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.