Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is it a special sign or it can be used as anything else? For creating variables for example.

$x=4
share|improve this question
5  
Nothing really special; usually it is used for denoting global constants, e.g. $MachineEpsilon, but you can certainly start your variables with a dollar sign. –  J. M. May 14 '13 at 13:00
    
Thanks a lot. At last something useful. –  Misery May 14 '13 at 13:01
3  
See also tutorial/BasicObjects in the free documentation... :) –  cormullion May 14 '13 at 13:16
add comment

1 Answer 1

up vote 14 down vote accepted

$ is probably the only non-alphanumeric ascii character without a special meaning in Mathematica and thus the only one you could use as a delimiter for various parts within a variable name.

A warning is due: Because it is so unique, it is also used internally for the same purpose, e.g. Module and Unique will generate variable names ending in $+ an arbitrary integer:

Unique[]
Module[{x},x]

In some cases, also Function will generate variable names ending in $ for its arguments. You can read more about this here. To stay out of potential problems I would not use variables ending in $ or $ + integer.

Another case where $ seems to be used as some kind of internal convention are symbols which serve as global variables like $FrontEnd,$Context, $Path ..., but you can avoid conflicts by using a lowercase letter for the second letter of the variable name.

Other than the mentioned cases, I wouldn't expect problems when using $ within variable names. It should be mentioned that due to the possibility to use non-ascii letters within variable names, people often use such characters for similar purposes, e.g.:

long\[Bullet]name

which will look nicer in the frontend, but won't render nice in the Wolfram Workbench editor.

share|improve this answer
    
@Ajasja: thanks for the link, I remember now that I read that once, but couldn't remember... –  Albert Retey May 14 '13 at 16:38
1  
You're welcome. You were right. Using $ at the end of a name can cause problems: f = Function[{x}, Function[{y}, x + y]]; o2 = f[2 y$]; o1 = f[2 y]; {o1[a], o2[a]} –  Ajasja May 14 '13 at 16:47
    
Here's another example of Function using $ internally, causing confusion to the user: mathematica.stackexchange.com/q/25563/5 –  rm -rf May 20 '13 at 21:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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