Identifier
Release: |
4.6 • 5.0 • 5.1 • 5.2 • 5.3 • 5.4 • 6.0 • 6.1 • 6.2 • 6.3 • 6.4 • 6.5 |
---|
An identifier is a unique name used to refer to a Variable, Function, or any other Class of Object or local value.
Titles and Identifiers
Each object has a Title as well as an Identifier. The Title normally appears in its node in a diagram, and in tables and graphs for variables. The Identifier is used in Definitions and other expressions.
When you create a new object, it automatically creates the identifier of the new object from the title, substituting '_' for spaces or other punctuation. It uses up to the first 48 characters.
Normally, diagrams, tables, and the Outliner show the Titles of variabes. You can switch between viewing Identifiers or Titles by pressing Ctrl+Y (or toggle Show by identifier on the Object menu). This shortcut becomes second-nature to seasoned model builders.
Features of identifiers
- Every global object has a unique identifier, including Variables, Models, Modules, user-defined and system Functions, Attributes, and so on. Local variables in Definitions and Function parameters also have identifiers, which must be unique within that Definition.
- Identifiers are case-insensitive. So,
Profit
,profit
,PROFIT
andprOFIt
are all the same identifier. They are sensitive to accents, but not to Unicode normalization. They are stored in the KC (aka NFKC) normalization form.
- An identifier normally starts with a letter, followed by zero or more letters or digits. It may include underscore '_', but not spaces or punctuation.
- In an expression, a Local identifier that is declared via the Local..Do or For..Do constructs refers to the value that was computed on the right-hand side of the
:=
when the local was declared, or to values subsequently assigned to the local.
- Inside a Function definition, a parameter identifier normally refers to the value that was passed by the caller. The exception is when the parameter has a Class Qualifier, such as (
Index
Object
,Variable
,Class
, orAttribute
) where the parameter refers to an object. You can use the identifier of these class parameters in the Function definition anywhere you could use the identifier of the original object.
You can't automatically tell whether an Identifier refers to a Global object or is a local variable or function parameter. So, many people use the convention of capitalizing global variables and indexes, and using lower case for local variables and function parameters.
Getting the identifier of an object
Every object has a unique identifier. You can access this underlying identifier using the expression
Identifier Of Time
returns "Time". This may seem pointless if you have to already know the identifier. But in some cases, you may use an expression to refer to the object. For example, if you pass the object as a parameter:
Function NameOfIndex(I: Index)
- Definition:
Identifier of I
Now call:
NameOfIndex(Time)
The result is "Time"
, not "I"
.
When an identifier names a value, you cannot access its identifier via an expression.
Local x := 4+5 Do (Identifier of X)
→ Error: 'Identifier Of x' does not exist.
Legal names for Identifiers
Identifiers can start with letters (Unicode categories Ll, Lm, Lo, Lt, Lu) and "letter numbers" (Unicode category Nl). Some built-in or internal identifiers start with an underscore '_', but user identifiers cannot. After the first character, subsequent characters include all the starting categories as well digits, underscores and Unicode categories Mc, Mn, Nd and Pc (spacing marks, non-spacing marks, decimal numbers and connector punctuation). These categories capture a natural sense of words in pretty much any language. In general, you can't use spaces or punctuation characters in identifiers (but you can in titles).
Backquotes for arbitrary characters in an identifier
You can use an Identifier that does not abide by these rules by surrounding it in backquotes. A backquoted identifier can contain pretty much any printable character except backquotes, newlines and unprintable control characters. If the characters excluding the surrounding backquotes qualify as a legal identifier without the backquotes, then the identifier with or without the backquotes are considered the same.
These are valid (allowed) identifiers:
- x
- Annual_Revenue
- Health_damage
- Revenue_by_product_category
- N14compliance
- Rank17
- A_b_c_d
- Te1261540435
- Disminución_diaria
- θ
- Απόσταση
- 升值率高于通货膨胀率
- Rennslishraði
- ความหนาแน่นของฟอเรสต์
- जनसंख्या_वृद्धि_दर
- `n!`
- `+`
- `Emission reduction ($)`
These are invalid names for identifiers(when not backquoted):
- A&B
- n!
- 4x
- _x --- Starting with underscore is reserved for system use
Note:
Ingreso
,INGRESO
and`Ingreso`
are all the same identifier (case-insensitive, backquote insensitive when legal).Ingreso
andIngresó
are different identifiers (accent-sensitive).Emission_reduction
and`Emission reduction`
are different identifiers (space and underscore are different)
Generating an identifier from the title
When you enter a title for an object, it usually automatically generates an identifier from the title. It may ask you if you want to rename it (the exact behavior can be configured on the Preference Dialog). It does this by replacing spaces and punctuation with underscores, converting Chinese character to their Pinyin romanizations, appending digits to the end to ensure uniqueness, etc. One "gotcha" to watch out for is the appending of digits when an object already exists with the same name. For example, if you title a variable NPV, it generates its Identifier as NPV1, because NPV is the name of a built-in function. This won't be obvious when you are viewing only the title on a diagram. In a Definition of another variable, you will need to use NPV1 in your expression.
One preference setting is the length of the identifier, which controls the maximum character limit for an identifier generated from a title. This defaults to
20
until you change it. You can increase it to allow for longer generated titles. It does not limit the length when you edit the Identifier
attribute directly. Excessively lengthy identifiers can detract from expression readability, but you may find a larger length to be convenient.
There is an option to use backquoted titles (with spaces and punctuation) as the identifier instead of replacing disallowed characters with underscores, etc. This option is experimental and not exposed on the Preference Dialog. To try this, in typescript type:
Naming:4
Use 5 if you want it to ask first before changing the identifier.
History
The set of legal identifiers was greatly enlarged in the Analytica 6.4 release to include:
- Non-english characters
- Identifiers longer than 20 characters.
- Backquoted identifiers for arbitrary text
- Removed the generation of pinyin identifiers from Asian language titles (Chinese, Japanese, Korean), since those character sets are now allowed.
To compare the differences, use the release bar at the top of this page to 6.3 or earlier or 6.4 or later.
Enable comment auto-refresher