© Tyl Software Foundation 2019-2021
▶ ACCESS & EDIT RECORDS
Adding/Removing Scalar Keys
To add a scalar key to a record:
product <- 'price' 10.0
price
property is added to product
, and its value will be 10.0.
The value can be omitted:
product <- 'price'
In this case, the value will be NULL.
price
key can be accessed and edited by the dot notation:
product { cat 'Electrical' name 'LED Light Bulb' }
product <- 'price' 10.0
print 'assigned price = ' + product.price
product.price 20
print 'updated price = ' + product.price
assigned price = 10
updated price = 20
updated price = 20
Alternatively, you can have a scalar variable as the property name:
product { cat 'Electrical' name 'LED Light Bulb' }
key 'price'
product <- key 10.0
print 'assigned ' + key + ' = ' + product key
assigned price = 10
Accessing a peoperty that was added with scalar variable,
is done dynamically only.
Removing a key is done by appending the remove item code '->', to the dynamic access statement:
Removing a key is done by appending the remove item code '->', to the dynamic access statement:
product 'price' ->
price
key is removed from product
, and its value is
returned.
Note that in remove item statements, the access statement must be dynamic.
Consider this program:
product { cat 'Electrical' name 'LED Light Bulb' }
print product
product <- 'price' 10.0
print product
removedprice product 'price' ->
print product
print
print 'removed price: ' + removedprice
{
cat: 'Electrical'
name: 'LED Light Bulb'
}
{
cat: 'Electrical'
name: 'LED Light Bulb'
price: 10
}
{
cat: 'Electrical'
name: 'LED Light Bulb'
}
removed price: 10
cat: 'Electrical'
name: 'LED Light Bulb'
}
{
cat: 'Electrical'
name: 'LED Light Bulb'
price: 10
}
{
cat: 'Electrical'
name: 'LED Light Bulb'
}
removed price: 10
In line '
removedprice product 'price' ->
', removedprice
gets the value of the item that
is being removed from product
.
Editing Scalar Keys
Editing a record is done by appending the value statement to the
record access statement:
product.name 'Fluorescent Light Bulb'
In line
Other options to edit a record:
product.name 'Fluorescent Light Bulb'
, product.name
is the
access statement, and it will be set to 'Fluorescent Light Bulb'.
Other options to edit a record:
product 'name' 'Fluorescent Light Bulb'
key 'name'
value 'Fluorescent Light Bulb'
product key value
values 'LED Light Bulb', 'Fluorescent Light Bulb'
product key values 1
In all these record edit statements,
product name
property will be set to
'Fluorescent Light Bulb'. In line product key values 1
, the section values 1
,
is the value statement,
so the second item of values
list will be the new value of product name
.