6
$\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$
4
  • 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$ Commented Apr 27, 2017 at 15:46
  • $\begingroup$ @DanielLichtblau Didn't you do that already? Function / Properties&Relations / 4th example. $\endgroup$
    – Kuba
    Commented Apr 27, 2017 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$ Commented Apr 27, 2017 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
    Commented Apr 28, 2017 at 8:02

1 Answer 1

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$
5
  • $\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
    Commented Apr 27, 2017 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$
    – webcpu
    Commented Apr 27, 2017 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
    Commented Apr 27, 2017 at 9:11
  • $\begingroup$ $ doesn't belong to Letters and Letter-like Forms in Wolfram Language. reference.wolfram.com/language/tutorial/… $\endgroup$
    – webcpu
    Commented Apr 27, 2017 at 9:55
  • $\begingroup$ Ok, but again, Unique does not say it only work with "user defined symbols". $\endgroup$
    – Kuba
    Commented Apr 27, 2017 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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