Difference between revisions of "Identifier"

(enhanced description and 6.4 rules for legal idents (started))
Line 1: Line 1:
 
[[category:Attributes]]
 
[[category:Attributes]]
 +
{{ReleaseBar}}
  
The identifier is the name of an Analytica object. Each object in Analytica's global name space has a unique identifier.
+
An identifier is a name that is used to refer to an Analytica object or to a (temporary) value.  
 +
* Each object in Analytica's global name space has a unique identifier. This includes all nodes in your model, built-in functions, system variables, attributes, classes, typescript commands, etc.
 +
* Inside a [[User-Defined Functions|Function]] definition, the identifiers of pass-by-value parameters refer to the value that was passed by the caller.
 +
* In an expression, a [[Local Values|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 <code>:=</code> when the local was declared, or to values subsequently [[Assignment Operator :=|assigned]] to the local.
 +
* Inside a [[User-Defined Functions|Function]] definition, the parameters declared with a class name (<code>Index</code> <code>Object</code>, <code>Variable</code>, <code>Variable</code>, <code>Class</code>, or <code>Attribute</code>) refer to objects. The identifier of the parameter is, in general, different from the identifier of the underlying object, but the parameter identifier can be used in the Definition expression.
 +
* In an expression, local identifiers declared using [[LocalIndex]] or [[LocalAlias]] constructs name objects. In general, the identifier of the local can be different from the identifier of the underlying object.
  
The identifier is an attribute of an Analytica object. So for example, the expression:
+
Although some identifiers refer to objects while other identifiers refer to values, the rules for what qualifies as a legal identifier name are the same in both cases. Thus, you cannot tell from the identifier [[Objects and Values|whether it names an object or a value]]. Many people adopt a stylistic convention of capitalizing identifiers that refer to objects, such as names of global variable and indexes, and using lower case for value identifiers.
 +
 
 +
== Underlying identifier of an object ==
 +
Every object has an identifier has its own identifier. You can access this underlying identifier using the expression
 
:<code>Identifier Of Time</code>
 
:<code>Identifier Of Time</code>
 
returns "Time".
 
returns "Time".
  
Identifiers must be between 1 and 20 characters in length, contain only letters A thru Z, digits 0 thru 9, and underscores, and the first character must be a letter. The capitalization of an [[Identifier]] is preserved when you enter it, so you can use "camel case" (capitalizing the first letter of each word, as in CamelCase); however, when you use an identifier in an expression, it is case insensitive. But the capitalization entered initially will be displayed whenever Analytica displays the identifier.
+
In some cases, the identifier you are using to refer to the object might be different from the underlying identifier. This occurs, for example, if you pass the object as a parameter. The following illustrates:
 +
 
 +
:<code>Function NameOfIndex( I : Index )</code>
 +
:'''Definition:''' <code>Identifier of I</code>
 +
 
 +
Now call:
 +
:<code>NameOfIndex( Time )</code>
 +
The result is <code>"Time"</code>, not <code>"I"</code>.
 +
 
 +
When an identifier names a value, you cannot access its identifier via an expression.
 +
:<code>[[Local]] x := 4+5 Do (Identifier of X)</code> &rarr; ''Error: 'Identifier Of x' does not exist.''
 +
 
 +
== Legal names for Identifiers ==
 +
Identifiers are case-insensitive. Thus, <code>Profit</code>, <code>profit</code>, <code>PROFIT</code> and <code>prOFIt</code> are all the same identifier.  {{Release|6.4||In addition they are accent sensitive, and Unicode normalization insensitive.}}
 +
 
 +
{{Release||6.3|Identifiers must be between 1 and 20 characters in length, contain only letters A thru Z, digits 0 thru 9, and underscores, and the first character must be a letter. The capitalization of an [[Identifier]] is preserved when you enter it, so you can use "camel case" (capitalizing the first letter of each word, as in CamelCase); however, when you use an identifier in an expression, it is case insensitive. But the capitalization entered initially will be displayed whenever Analytica displays the identifier.}}
 +
 
 +
{{Release|6.4||Identifiers can start with letters (Unicode categories Ll, Lm, Lo, Lt, Lu) and "letter numbers" (Unicode category Nl). Some built-in or internal identifiers may 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, spaces and punctuation characters are disallowed in identifiers (but may appear in titles).
 +
 
 +
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.
 +
}}
 +
 
 +
The following are examples of legal (allowed) identifiers:
 +
* x
 +
* Annual_Revenue
 +
* Health_damage
 +
* Revenue_by_product_c{{Release|6.4||ategory}}
 +
* N14compliance
 +
* Rank17
 +
* A_b_c_d
 +
* Te1261540435{{Release|6.4||
 +
* Disminución_diaria
 +
* 升值率高于通货膨胀率
 +
* Rennslishraði
 +
* ความหนาแน่นของฟอเรสต์
 +
* `n!`
 +
* `+`
 +
* `Emission reduction ($)`
 +
}}
 +
 
 +
 
  
 
When you enter a title for an object, Analytica will usually automatically generate an identifier from the title, and 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. So, for example, if you title a variable NPV, the automatically generated [[Identifier]] is NPV1, which isn't 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. The 1 appends here because the name [[NPV]] is already used by the built-in function.
 
When you enter a title for an object, Analytica will usually automatically generate an identifier from the title, and 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. So, for example, if you title a variable NPV, the automatically generated [[Identifier]] is NPV1, which isn't 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. The 1 appends here because the name [[NPV]] is already used by the built-in function.

Revision as of 19:53, 28 September 2023



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 name that is used to refer to an Analytica object or to a (temporary) value.

  • Each object in Analytica's global name space has a unique identifier. This includes all nodes in your model, built-in functions, system variables, attributes, classes, typescript commands, etc.
  • Inside a Function definition, the identifiers of pass-by-value parameters refer to the value that was passed by the caller.
  • 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, the parameters declared with a class name (Index Object, Variable, Variable, Class, or Attribute) refer to objects. The identifier of the parameter is, in general, different from the identifier of the underlying object, but the parameter identifier can be used in the Definition expression.
  • In an expression, local identifiers declared using LocalIndex or LocalAlias constructs name objects. In general, the identifier of the local can be different from the identifier of the underlying object.

Although some identifiers refer to objects while other identifiers refer to values, the rules for what qualifies as a legal identifier name are the same in both cases. Thus, you cannot tell from the identifier whether it names an object or a value. Many people adopt a stylistic convention of capitalizing identifiers that refer to objects, such as names of global variable and indexes, and using lower case for value identifiers.

Underlying identifier of an object

Every object has an identifier has its own identifier. You can access this underlying identifier using the expression

Identifier Of Time

returns "Time".

In some cases, the identifier you are using to refer to the object might be different from the underlying identifier. This occurs, for example, if you pass the object as a parameter. The following illustrates:

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 are case-insensitive. Thus, Profit, profit, PROFIT and prOFIt are all the same identifier. In addition they are accent sensitive, and Unicode normalization insensitive.


Identifiers can start with letters (Unicode categories Ll, Lm, Lo, Lt, Lu) and "letter numbers" (Unicode category Nl). Some built-in or internal identifiers may 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, spaces and punctuation characters are disallowed in identifiers (but may appear in titles).

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.

The following are examples of legal (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 ($)`


When you enter a title for an object, Analytica will usually automatically generate an identifier from the title, and 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. So, for example, if you title a variable NPV, the automatically generated Identifier is NPV1, which isn't 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. The 1 appends here because the name NPV is already used by the built-in function.

In most Analytica windows, including diagrams, tables, and the outliner, you can toggle between viewing Identifiers or Titles by pressing Ctrl+Y (on toggling Show by identifier on the Object menu). This shortcut becomes second-nature to seasoned model builders.

See Also

Comments


You are not allowed to post comments.