Post Reply 
variable name characters allowed.
11-15-2017, 11:50 AM
Post: #1
variable name characters allowed.
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.
Find all posts by this user
Quote this message in a reply
11-15-2017, 02:48 PM
Post: #2
RE: variable name characters allowed.
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."

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
11-15-2017, 06:47 PM
Post: #3
RE: variable name characters allowed.
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.
Find all posts by this user
Quote this message in a reply
11-15-2017, 06:52 PM
Post: #4
RE: variable name characters allowed.
%1 doesn't work in [CAS].
Find all posts by this user
Quote this message in a reply
11-15-2017, 07:10 PM
Post: #5
RE: variable name characters allowed.
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.
Find all posts by this user
Quote this message in a reply
11-16-2017, 05:52 AM
Post: #6
RE: variable name characters allowed.
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]

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
11-16-2017, 06:13 AM
Post: #7
RE: variable name characters allowed.
Ah, interesting....of course! It's unicode. I forgot about that. Thanks Cyrille.
-Donald
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)