HP Forums

Full Version: variable name characters allowed.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to know what characters can be used in a variable name and also as the first character in the name. e.g. V_1 is a valid variable name, but _V1 is not. Also, there are "other" characters from the Char key that are allowed, but I don't know how to tell which ones are valid. e.g. %1 is valid, but $1 is not. Likewise some of the odder characters like the w omega character is valid, and others are not. I test them by trying them out.
Anyway, if anyone knows whats valid in the name and also what is valid for the first character...please let me know.

Note that while I can use regular alpha chars, I was thinking there might be uses in obfuscation for those who want to protect their program code.
The HP Prime User Guide says this: "The name of a variable must be a sequence of alphanumeric characters (letters and numbers), starting with a letter. Names are case-sensitive, so the variables named MaxTemp and maxTemp are different."
Yet %1 is not alpha numeric and there are other weird characters that are not alphanum, like a zeta with a circle at the center....from the Char button.
%1 doesn't work in [CAS].
That's interesting. I can do %1:=1 in Home, but not in CAS and when defined in Home, to try to read %1 in CAS doesn't work, but it does in HOME.
Here is the code that identifies an identifier (var names and the like)


Int FindEndOfValidIdentifier(wchar_t const *s, wchar_t DecSeparator)
  if (DecSeparator==L'\0') DecSeparator= Calc->DecSeparator();
  wchar_t const *S= s;
  if (*s==L'\uE003' || (*s==L'\u03c0' && s[1]<128)) return 1;   // complex i, pi with non unicode after...
  if ((*s<L'A' || (*s>L'Z' && *s<=L'_') || (*s>L'z' && *s<128) || *s==L'\u25b6') && *s!=L'%') return 0; s++;
  while (((*s>=L'A' && *s<=L'Z') || *s==L'_' || (*s>=L'a' && *s<=L'z') || (*s>=L'0' && *s<=L'9') || *s>=128) &&   // In 7 bit ascii, only allows 0-9, A-Z, a-z. 
          !(*s==L'\u25B6' || *s==L'\uE004' ||                                                                     // Above 128, disable, Sto -1    
            *s==L'\u2212' || *s==L'\u00b2' || *s==L'\u221a' || *s==L'\u2264' || *s==L'\u2260' || *s==L'\u2265'))  // neg(-) ┬░ sqrt <= # >= 
  return s-S;

Ah, interesting....of course! It's unicode. I forgot about that. Thanks Cyrille.
Reference URL's