Chapter II - SPEL in Nutshell
The tSM Spring Expression Language (SpEL) is built upon a straightforward yet powerful syntax that allows for complex expressions.
This chapter introduces you, through the examples, to most of the main concepts, elements, and components of tSM SpEL. Detailed explanation, of each part shown here, is then provided in the very next chapter.
Note: If you are completely new to SpEL and just starting with tSM, you can as well jump over this chapter and go directly to the chapter III, where is everything explained in the detail.
2.1 SpEL Console Usage
- Press
CTRL
+SPACE
once in SpEL Console to see the autocomplete options. - Press
CTRL
+SPACE
twice to see descriptions of selected methods as well. - Press
CTRL
+ENTER
to evaluate whole script. - Select expression and press
Ctrl+Enter
to evaluate only that expression.
2.2 Example Script Structure
{
// Example script structure
#orderTotal = 250,
#discountedTotal = #orderTotal - 50,
#date = #now().formatted('dd-MM-YYYY HH:mm'),
#user = @userPublicService.getUser(#currentUser()).name,
#orderSummary = 'Price: ' + #discountedTotal + '; Date: '+ #date + '; User: ' + #user
}
Note: In the example, you can see that script is starting and ending with delimiters '', that there is ',' after each expression, except for the last one, that variables are starting with '#' and a services with '@'. To find out more about syntax, see chapter
2.3 Literals and Evaluations
Literals represent constant values in expressions. Literals available:
String
Decimal Number
Floating-Point Number
Hexadecimal Number
Number in Scientific Notation
Boolean
Null
{
// Literals
'Hello World', // Evaluates as 'Hello World' and it's a String
1234, // Evaluates as 1234 and it's a Decimal Number
123.4, // Evaluates as 123.4 and it's Floating-Point Number
0x7FFFFFFF, // Evaluates as 2147483647 and it's a Hexadecimal Number
6.0221415E+23 // Evaluates as 6.0221415E+23 and it's a Number in Scientific Notation
true, // Evaluates as true and it's a Boolean
null // Evaluates as null and it's a Null
}
Hint: Most of the examples in this guide could be directly copied into SPEL console and should work straight away. Easiest way to copy the script is to use small green icon in the right corner of each script.
2.4 Variable Assignment
Assign
ing values to variables for later use in expressions. Operator: =
{
// Variable Assignment
#myVariable = 'Some Value',
#anotherVariable = 42,
#customer = @customerPublicService
}
2.5 Expression Templating
Combining literals and variables to create dynamic strings. Operator: +
{
// Expression Templating using '+' operator
#name = 'John Doe',
#greeting = 'Hello, ' + #name + '!'
}
2.6 Data Types
Different types of data that can be used in tSM SpEL. Commonly used data types are:
String
Integer
Double
Boolean
List
Map
Object
JsonNode
Spreadsheet
Date
UUID
Null
But if you need, for any specific reason, you can use as well:
Long
BigDecimal
BigInteger
Array
Byte Array
Set
Enum
Calendar
{
// Common Data Types
#myString = 'Hello, world!', // String
#myInteger = 123, // Integer
#myDouble = 123.45, // Double; or in Scientific Notation #myDouble = 1.2345e2
#myBoolean = true, // Boolean
#myArray = new int[]{1, 2, 3, 4}, // Array
#myList = {'order', 'ticket', 'process', 'customer'}, // List
#myMap = {'customerName': 'Alpha', 'numberOfEmployees': 100}, // Map
#myObject = @userPublicService.currentUser, // Object
#myJsonNode = '{"name": "John", "age": 30}'.toJsonNode(), // JsonNode
#mySpreadsheet = #spreadsheet, // Spreadsheet
#myDate = #now(), // Date
#myUUID = #randomUUID(), // UUID
#myNull = null // Null
}
2.7 Basic Operations and Operators
2.7.1 Arithmetic Operators
Used to perform arithmetic operations. Operators available: +
, -
, *
, ^
, / or div
, % or mod
{
// Arithmetic Operations
#addition = 1 + 2, // 3
#subtraction = 5 - 2, // 3
#multiplication = 3 * 4, // 12
#exponentiation = 2 ^ 3, // 8
#division = 10 / 2, // 5; or #division = 10 div 2
#modulus = 10 % 3 // 1; or #modulus = 10 mod 3
}
Note: In most of the scripts in this guide, first value after '//' is how the expression is evaluated.
2.7.2 Relational Operators
Used to compare two values. Operators available: == or eq
, != or ne
, < or lt
, > or gt
, <= or le
, >= or ge
{
// Relational Operations
#isEqual = 1 == 1, // true; or #isEqual = 1 eq 1
#isNotEqual = 1 != 2, // true; or #isNotEqual = 1 ne 2
#isLessThan = 1 < 2, // true; or #isLessThan = 1 lt 2
#isGreaterThan = 2 > 1, // true; or #isGreaterThan = 2 gt 1
#isLessThanOrEqual = 1 <= 1, // true; or #isLessThanOrEqual = 1 le 1
#isGreaterThanOrEqual = 2 >= 1, // true; or #isGreaterThanOrEqual = 2 ge 1
// It's possible to compare strings as well.
#isEqualString = 'is' == 'is', // true
#isNotEqualString = 'is' != 'not' // true
}
2.7.3 Logical Operators
Used to perform logical operations. Operators available: && or and
, || or or
, ! or not
{
// Logical Operations
#logicalAnd = true && false, // false; or #logicalAnd = true and false
#logicalOr = true || false, // true; or #logicalOr = true or false
#logicalNot = !true // false; or #logicalNot = not true
}
2.8 Data Access
2.8.1 Property and Key Access
Accessing values in 'Maps' and 'Objects' by their 'Keys' or 'Properties'. Operators: .
, ['key']
{
// Accessing 'Object Property' and 'Map Key'
// You have this map, for example: (works same with objects)
#myMap = {'name':'Your company', 'address':{'street':'Na padesátém','city':'Prague'}},
// And you need to access the value of 'name' and nested value of 'street' key/property
#myMap.name, // 'Your company'; Key/property access; Or you can use #myMap['name']
#myMap.address.street // 'Na padesátém'; Nested key/property access; Or #myMap['address']['street']
}
2.8.2 List Item Access
Accessing 'Items' in a 'List' by their index. Operator: [index]
{
// Accessing 'List Items'
#myList = {'order', 'task', 'process'},
#myList[0] // 'order'; List item access by index
}
2.8.3 Collection Selection and Collection Projection
Collection Selection: Selecting items from a collection based on specific criteria. Operator: .?[condition]
Collection Projection: Projecting specific properties of items in a collection. Operator: .![key]
{
// Collection Selection and Collection Projection
// You have this 'List of Maps', for example:
#services = [{'name': 'Int', 'price': 10}, {'name': 'TV', 'price': 15}, {'name': 'Phone', 'price': 5}],
// Selecting services with price greater than 9
#sel = #services.?[price > 9], // [{'name': 'Int', 'price': 10}, {'name': 'TV', 'price': 15}]; Collection Selection
// Projecting the names of the selected services
#serviceNames = #sel.![name], // ['Int', 'TV']; Collection Projection
// Or you can combine them in one step
#selectedServiceNames = #services.?[price > 50].![name], // Combined selection and projection
#selectedServiceNames // ['Int', 'TV']
}
2.9 Flow Control and Ternary Operator
Controlling the flow of execution in expressions.
2.9.1 Condition based Flow Control
Condition-based flow control operators allow you to execute expressions based on specific conditions, providing a way to handle different scenarios dynamically. Operators available:
#if(cond1).then(exp1).elseif(cond2).then(exp2).else(exp3)
#match(var1).when(valueOfVar1,exp1).else(exp2)
#case().when(cond1,exp1).else(exp2)
{
// If-then-elseif-then-else Flow Control
#total =99,
#if(#total > 200).then(#discount = 0.2).elseif(#total > 100).then(#discount = 0.1).else(#discount = 0.05) // 0.05
}
{
// Match-when-else Flow Control
#technologyAvailable = '5G',
#match(#technologyAvailable).when('5G',#provision = 'mobile').else(#provision='fix') // 'mobile'
}
2.9.2 Block based Flow Control
Block-based flow control operators allow you to group expressions and execute them together, making it easier to manage complex logic. Operators available:
#with(exp1,exp2).do(exp3)
#do(exp1, exp2)
{
// With-do Flow Control
#with(
#orderTotal = 250,
#orderDiscount = 0.1,
#discountedTotal = #orderTotal - (#orderTotal * #orderDiscount)
).do(#orderType =
#case().when(#orderTotal > 100, 'Large Order').else('Small Order')
) // 'Large Order'
}
2.9.3 Iteration
Iteration operators
allow you to loop through collections and execute expressions for each item, providing a way to handle repetitive tasks. Operators available:
.forEach(var1, exp1, exp2)
{
// Iteration using forEach
#numbers = [1, 2, 3, 4],
#squares = [],
#numbers.forEach(#num, #squares.add(#num * #num)) // [1, 4, 9, 16]
}
2.9.4 Ternary Operator
The ternary operator is a concise way to perform conditional logic in place of an if-then-else statement. It simplifies the code and enhances readability, especially for simple conditions.
{
// Ternary Operator Flow Control
#orderTotal = 150,
#orderType = #orderTotal > 100 ? 'Large Order' : 'Small Order', // 'Large Order; Ternary Operator
}
2.10 Null Safety and Error Handling
2.10.1 Null Safety Operator
The null safety operator helps prevent NullPointerExceptions by allowing safe navigation through potential null references.
{
// Safe navigation through potential null references - Null Safety Operator
#order = {'customer': null},
#customerName = #order.customer?.name // null if customer is null
}
2.10.2 Default Value Setting - Elvis Operator
The Elvis operator provides a shorthand for assigning default values when expressions evaluate to null.
{
// Default value assignment using Elvis Operator
#customerName = null,
#displayName = #customerName ?: 'Unknown Customer' // 'Unknown Customer'
}
2.10.3 Error Catching
The try-catch construct allows handling exceptions within SpEL expressions.
{
// Exception handling using Try-catch Flow Control
#result = #try(
#riskyOperation()
).catch(
'Error occurred'
)
}
2.11 Built-in Methods
tSM SpEL contains a wide range of built-in methods for various data manipulations and operations.
2.11.1 Standalone Methods
Standalone methods available:
#currentUser()
#isNotEmpty(value)
#isNullOrEmpty(value)
#jsonToString(value)
#now()
#objectToMap(value)
#randomTrueFalse()
#randomUUID()
{
// Using Built-in Standalone Methods
#currentUserId = #currentUser(), // Current user UUID
#isNonEmpty = #isNotEmpty('some string') // true
}
2.11.2 String Methods
Comparison methods (returning true/false):
isBlank()
isEmpty()
isNotBlank()
isNotEmpty()
contains(other,ignoreCase)
startsWith(other,ignoreCase)
Conversion methods:
decodeBase64()
toBoolean()
toByteArray()
toDate(format)
toJsonNode()
toUuid()
Data manipulation methods:
lowercase()
uppercase()
replace(oldValue, newValue)
padStart(length, padChar)
{
// Using String Methods
#string = 'Hello, World!', // "Hello, World!"
#lowercased = #string.lowercase(), // "hello, world!"
#containsHello = #string.contains('Hello') // true
}
2.11.3 List Methods
List methods:
size()
get(index)
indexOf(element)
first()
last()
min()
max()
distinct()
distinctCount()
sorted()
reversed()
take(n)
drop(n)
zipWith(list2)
subList(fromIndex, toIndex)
minus(minusList)
forEach(varRef, expressions)
{
// Using List Methods
#list = [3, 1, 2, 3], // [3, 1, 2, 3]
#distinctList = #list.distinct(), // [3, 1, 2]
#sortedList = #distinctList.sorted() // [1, 2, 3]
}
2.11.4 Map Methods
Map methods:
containsKey(key)
containsValue(value)
get(key)
isEmpty()
keys()
size()
values()
withRemovedKey(removeKey)
withRemovedKeys(removeKeys)
withRemovedKeysRecursive(removeKeys)
withReplacedValuesRecursive(replacekey, replaceValue, newValue)
{
// Using Map Methods
#map = {'name': 'john', 'surname': 'Doe'}, // {'name': 'john', 'surname': 'Doe'}
#containsName = #map.containsKey('name'), // true
#mapSize = #map.size() // 2
}
2.11.5 Date Methods
Date methods:
addIntervalPercentage(dateTo, percent)
endOfMonth()
endOfYear()
formatted(format)
formatted(format, zone)
isAfter(secondDate)
isBefore(secondDate)
iso()
minus(duration)
minusDays(daysCount)
minusHours(hoursCount)
minusMinutes(minutesCount)
minusMonths(monthsCount)
minusSeconds(secondsCount)
plusDays(daysCount)
plusDuration(duration)
plusHours(hoursCount)
plusMinutes(minutesCount)
plusMonths(monthsCount)
plusSeconds(secondsCount)
setMidnight()
setTime(hours, minutes, seconds, zone)
startOfMonth()
startOfYear()
{
// Date Methods
#now = #now(), // Todays date in Java Date format
#formattedDate = #now.formatted('dd-MM-yyyy'),// Todays date in format 'dd-MM-yyyy'
#nextWeek = #now.plusDays(7).iso() // Date 7 days from now, in iso format
}
2.11.6 Spreadsheet Methods
Spreadsheet methods:
addSheet(name)
addStyle(id)
deleteSheet(name)
deleteStyle(id)
get(index)
get(name)
getSheet(name)
getStyle(id)
getStyle(index)
set(index, value)
sheets()
styles()
{
// Spreadsheet Methods
#newSpreadSheet = #spreadsheet,
#newSpreadSheet.addSheet('NewSheet'),
#sheet = #newSpreadSheet.getSheet('NewSheet')
}
2.12 Context Variables
Context variables provide access to various aspects and provide informarmation about the current execution context in tSM.
#order
: Represents the current order being processed.#ticket
: Represents the current ticket.#task
: Represents the current task.#variables
: Accesses global variables.#variablesLocal
: Accesses local variables specific to the current scope.#execution
: Represents the current execution context.
{
// Context Variables
#orderProductCodes = #order.productCodes(), // Get list of product codes processed within order
#completedTask = #task.complete(), // Finish the current task and move process forward
#processInfo = #execution.processInstance, // Get information about running Process
#ticketStatus = #ticket.status // Retrieves status of current running ticket
}
2.13 tSM Services
tSM services are powerful tools that allow you to interact with various functionalities within the tSM platform. Using them you can manipulate every entity of the tSM platform, create various API calls and use them as part of integration with another platfrom. To these there are about 1500 methods of tSM services available, so they can't be listed here, but we will look at them deeper in chapter III. Standard syntax of tSM Service is @tsmService.tsmMethod
.
{
// Using tSM Services
#currentUser = @userPublicService.getUser(#currentUser()), // Retrieves information about current user
#customer = @tsmDatabaseClient.query(
"select id,key from crm.crmt_customer").execute().last().id, // Retrieve ID of last cutomer in db
#account = @personPublicService.getPersonByCustomerId(#customer) // Retrieves all information of the customer's persons
}
Hint: To explore tSM Services, you can leverage the autocomplete option of the tSM Console or open the 'tSM Public API' item in the main menu of the tSM Platform. Here, you will find the Swagger documentation for all available services, as well as Public API operations.
2.14 Advanced Expressions and Constructs
2.14.1 Class Expressions
Class expressions allow you to access static methods and fields of a class directly within SpEL.
{
// Accessing static method with Class Expressions
#sqrtResult = T(java.lang.Math).sqrt(16) // 4; Calculates the square root of 16
}
2.14.2 Regular Expressions
Regular expressions provide powerful pattern matching capabilities within SpEL.
{
// Matching values using Regular Expressions
#matches = '192.168.0.2'.matches(
'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$') // true; Check value if it's correctly written IP address
}
2.15 Complex Script Example
Following script includes most of the concepts discussed in this chapter
{
#with(
// Primitive Data Types
#orderTotal = 250,
#orderDiscount = 0.1,
#orderStatus = 'Pending',
#notificationSent = false,
#priority = false,
#customerName = 'John Doe',
// Collections - List and Map
#adminEmails = ['admin1@telco.com', 'admin2@telco.com'], // List
#services = [{'name': 'Internet', 'price': 100},
{'name': 'TV', 'price': 150},
{'name': 'Phone', 'price': 50}], // Map
// Basic Operations
#discountedTotal = (#orderTotal - (#orderTotal * #orderDiscount)), // Arithmetic Operations
#isLargeOrder = #orderTotal > 100, // Relational Operation: '>'
// Ternary and Elvis Operators
#orderType = (#isLargeOrder ? 'Large Order' : 'Small Order'), // Ternary Operator
#isPriority = (#isLargeOrder ? true : false),
#customerNameSafe = (#customerName ?: 'Unknown Customer'), // Elvis Operator
// Collection Projection and Collection Selection
#selectedServices = #services.?[price > 50], // Collection Selection
#serviceNames = #services.![name], // Collection Projection
// tSM Service (@notificationPublicService), tSM Method (.sendNotification)
// Flow Controls: if-then-else and forEach
#sendNotification = #if(#isPriority and !#notificationSent).then(
#adminEmails.forEach(#email, @notificationPublicService.sendNotification({
"templateCode": "TaskAssigned",
"ownerId": #currentUser(),
"ownerType": "Order",
"notificationTo": [
{
"ownerId": #currentUser(),
"ownerType": "User"
},
{
"email": "peter.yan@google.com"
}
],
"data": {
"order": #order,
"task": #task
}
})),
#notificationSent = true
).else('Notification not needed')
).do(
{
// Returned result from script
'Total Amount: ' + #orderTotal.toString(), // Usage of built-in method: toString()
'Discounted Total: ' + #discountedTotal.toString(),
'Order Status: ' + #orderStatus,
'Order Type: ' + #orderType, // Expression Templating: 'string' + #var
'Priority Order: ' + #isPriority,
'Customer Name: ' + #customerNameSafe,
'Services: ' + #serviceNames.toString(),
'Selected Services: ' + #selectedServices.toString(),
'Notification Sent: ' + #notificationSent
}
)
}
Chapter III - Deep Dive Into
3.1 SpEL Console
3.1.1 Accessing Console
There are generally two ways to open the SpEL console:
- Without Context
- With Context
We will discuss these options in more detail later in chapter 3.x.x. Essentially, 'with context' means that you are opening the console within an entity that has a running process instance. The most common examples are orders and tickets, but it can include other entities depending on your implementation. The difference between opening the SpEL console 'with' or 'without context' is that in the case of "with context," you have 'context variables' available, providing important information about the entity you opened the SpEL console in.
For example, if you open the SpEL console within a running order, you have the #order
context variable available with all the information about the order.
Opening the console WITHOUT CONTEXT:
In this case, you simply type spel
in the search box of the tSM main left menu and click on the 'Spel Console' menu item that appears, or you can manually find the 'Spel Console' menu item in the left menu.
Opening the console WITH CONTEXT:
In this case, you open the details of a running instance of, for example, an order or a ticket. In the top right corner, click on the three dots, and in the menu that appears, click on 'Spel Console'.
3.1.2 Autocomplete Options
The tSM console provides several shortcuts and practical tips to help you work more efficiently, and one of those is the autocomplete option:
-
Ctrl+Space
Opens the autocomplete suggestions for partially typed expressions, helping you quickly find available functions, methods, and variables. You can navigate between suggestions using the arrow keys and insert the chosen suggestion by pressing enter or by any mouse button. -
@ and Ctrl+Space
On a new line, type@
and then pressCtrl-Space
. The console will provide a list of all available tSM Services. -
# and Ctrl+Space
On a new line, type#
and then pressCtrl-Space
. The console will provide a list of standalone built-in methods, variables, context variables, and flow control operators. -
2x Ctrl+Space
When you pressCtrl+Space
twice, the console will provide a description of the currently selected item in the suggestion list. -
Enter within ‘()’
When you pressEnter
within the brackets of a method with the opened suggestion list, it will provide example values for that method.
3.1.3 Script and Expression Evaluation
-
Ctrl-Enter
- Evaluates the current script, displaying the result in the output section of the console. -
Selection and Ctrl-Enter
- When you select within the whole script only one expression, and pressCtrl-Enter
, only the selected expression will be evaluated. This is a good way to test partial parts of the script. However, you can only evaluate one expression at a time.
Note: Using these shortcuts can significantly speed up your workflow and reduce errors.
Hint: For complete tSM Services and Public API documentation, refer to the "Public API" item in the main menu of the tSM platform.
3.2 tSM SpEL Syntax
3.2.1 Expression Definition
In tSM SpEL, an expression is any valid piece of code that can be evaluated and return a single result (single value, collection, or object). Expressions can be simple or composite, involving variables, method calls, operators, and other constructs.
Note: It is important to understand what an expression is, at least because of expression separation rules, as defined in chapter '3.2.2.3 Expression Separation'.
3.2.1.1 Simple Expression
A simple expression is one where a single operation or command is performed, such as assigning a value to a variable, calling a method, performing an arithmetic operation, logical operation, accessing an array or object property, and more.
Example of a single simple expression:
#listOfCustomers = @tsmDatabaseClient.query("select name from crm.crmt_customer").execute()
3.2.1.2 Composite Expression
A composite expression can contain multiple simple expressions, operations, and commands, but is considered a single expression as the result is evaluated as a whole and returned as a single value. It is important to understand that all expressions that return a single result are considered a single expression regardless of their complexity.
The following example is therefore also a single expression:
#finalResult = @calculateService.calculate(
#variable = @someCommand(#input),
#if(#variable > 10)
.then(@logService.log('High value'), 'High value')
.else(@logService.log('Low value'), 'Low value')
)
This composite expression includes assignment, an if-then-else
condition, method calls, and assignment of the final value. All these operations are performed within a single expression, which means that it is evaluated as a whole, and the result of the entire expression is assigned to the variable #finalResult
.
3.2.2 tSM SpEL syntax rules
3.2.2.2 Script Structure:
Scripts start with delimiter {
and end with delimiter }
. Delimiters []
can be used as well. This rule applies to all scripts, only exception when it's not mandatory is for single expression scripts, but we advise using delimiters in all cases.
{
#var1 = 'Hello',
#var2 = 'World',
console.log(name.toUpperCase());
// Uncaught TypeError: Cannot read properties of null (reading 'toUpperCase')
#result = #var1 + ' ' + #var2
}
3.2.2.3 Expression Separation
Expressions, whether in the script body or within a block body, are separated by
commas, except for the last expression in the script or block.
In the following example, each line ends with statements indicating:
- whether the line is an expression (isExpression), whether it is part of a script (withinScript) or a block (withinBlock),
- whether it is or is not the last expression in the script/block (isLast/isNotLast), and whether or not the use of a comma is implied (commaUsed/commaNotUsed).
{
#prvyVyraz = 'Hello ', isExpression withinScript isNotLast -> commaUsed
#druhyVyraz = 'Earth', isExpression withinScript isNotLast -> commaUsed
#tretiVyraz = #if(#druhyVyraz != 'World').then(
#druhyVyraz=' World ', isExpression withinBlock isNotLast -> commaUsed
#now().iso() isExpression withinBlock isLast -> commaNotUsed
), isExpression withinScript isNotLast -> commaUsed
#piatyVyraz = #prvyVyraz + #druhyVyraz + #tretiVyraz isExpression withinScript isLast -> commaNotUsed
}
3.5 Assigning Values to Variables
Assigning values to variables is straightforward. Use the =
operator:
#myVariable = 'New Value'
#myNumber = 10
3.2.2.4 Data Types Usage
Each data type is written and called/used with #
at its beginning.
{
#sompremenna = 4 // Creates variable `#sompremenna` and assigns it the value `4`
#if(#sompremenna > 3).then('táto premenna má väčšiu hodnotu ako 3')
}
3.2.2.5 Standalone Built-in Methods Usage
Each basic method is called/used, if it does not directly follow a data type or another method, also with #
at its beginning.
{
#now() // Returns the current time in Java Date format
}
3.2.2.6 Linked Methods Usage
Each method, if it directly follows a data type, another method, or a service, starts with .
.
{
'som string'.uppercase() // Result: 'SOM STRING'
}
3.2.2.7 tSM Services and Methods Usage
Each tSM service is written/called with @
at its beginning.
The service itself does not perform any function but provides a specific set of methods that need to be called as mentioned in point 4.
{
@customerPublicService.findCustomer(#idOrKey)
}
3.2.2.8 Flow Control Operators Usage
Each operator, if used independently or as the first in a chain of operators, is written with #
at the beginning.
{
#do(something)
}
Each operator, if following another operator, is written with .
at the beginning.
{
#if(something).then(doSomething)
}
3.2.2.9 Operator Body
The body of each operator is enclosed in ()
.
{
#with(totoJeTeloOperatoraWith).do(totoJeTeloOperatoraDo)
}
3.2.2.10 Assigning Values
Values are assigned to all data types using the =
operator.
{
#premenna = 3,
#inaPremenna = {1, 2}
}
3.2.2.11 Changing Data Type
By assigning a value using =
, if the variable already existed before the assignment, its data type changes to the one identified in the current assignment, and the original value is overwritten with the new value.
3.2.2.12 Automatic Data Type Initialization
Data types do not need to be specified or pre-initialized; they are automatically initialized and determined based on the structure or values assigned to the data type.
3.6 Using , [], ()
-
Curly Braces
{}
: Used for block expressions.-
Example:
{
#var1 = 'Hello',
#var2 = 'World',
#result = #var1 + ' ' + #var2
}
-
-
Square Brackets
[]
: Used for array and list access.- Example:
#myList[0]
- Example:
-
Parentheses
()
: Used for grouping and method calls.- Example:
(#number + 5) * 2
- Example: