Target Language Compiler | ![]() ![]() |
Identifier Definition
To define or change identifiers (TLC variables), use the directive
This directive introduces new identifiers (variables) or changes the values of existing ones. The left side can be a qualified reference to a variable using the .
and []
operators, or it can be a single element of a vector or matrix. In the case of the matrix, only the single element is changed by the assignment.
The %assign
directive inserts new identifiers into the local function scope (if any), file function scope (if any), generate file scope (if any), or into the global scope. Identifiers introduced into the function scope are not available within functions being called, and are removed upon return from the function. Identifiers inserted into the global scope are persistent. Existing identifiers can be changed by completely respecifying them. The constant expressions can include any legal identifiers from the .rtw
files. You can use %undef
to delete identifiers in the same way that you use it to remove macros.
Within the scope of a function, variable assignments always create new local variables unless you use the ::
scope resolution operator. For example, given a local variable foo
and a global variable foo
In this example, the assignment always creates a variable foo
local to the function that will disappear when the function exits. Note that foo
is created even if a global foo
already exists.
In order to create or change values in the global scope, you must use the scope resolution operator (::
) to disambiguate, as in
The scope resolution operator (::)
forces the compiler to assign to the global foo
, or to change its existing value to 3.
Creating Records
Use the %createrecord
directive to build new records in the current scope. For example, if you want to create a new record called Rec
that contains two items (e.g., Name "Name" and Type "t"), use
Adding Records
Use the %addtorecord
directive to add new records to existing records. For example, if you have a record called Rec1
that contains a record called Rec2
, and you want to add an additional Rec2
to it, use
This figure shows the result of adding the record to the existing one.
If you want to access the new record, you can use
In this same example, if you want to add two records to the existing record, use
%addtorecord Rec1 Rec2 { Name "Name1"; Type "t1" } %addtorecord Rec1 Rec2 { Name "Name2"; Type "t2" }
Adding Parameters to an Existing Record
You can use the %assign
directive to add a new parameter to an existing record. For example,
%addtorecord Block[Idx] N 500 /% Adds N with value 500 to Block %/ %assign myn = Block[Idx].N /% Gets the value 500 %/
adds a new parameter, N
, at the end of an existing block with the name and current value of an existing variable as shown in this figure. It returns the block value.
![]() | TLC Reserved Constants | Variable Scoping | ![]() |