HP Forums
variable name characters allowed. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: variable name characters allowed. (/thread-9495.html)



variable name characters allowed. - webmasterpdx - 11-15-2017 11:50 AM

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.


RE: variable name characters allowed. - Joe Horn - 11-15-2017 02:48 PM

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."


RE: variable name characters allowed. - webmasterpdx - 11-15-2017 06:47 PM

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.


RE: variable name characters allowed. - DrD - 11-15-2017 06:52 PM

%1 doesn't work in [CAS].


RE: variable name characters allowed. - webmasterpdx - 11-15-2017 07:10 PM

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.


RE: variable name characters allowed. - cyrille de brébisson - 11-16-2017 05:52 AM

Hello,
Here is the code that identifies an identifier (var names and the like)

Code:

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 <= # >= 
    s++;
  return s-S;
}

Cyrille[/code]


RE: variable name characters allowed. - webmasterpdx - 11-16-2017 06:13 AM

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