TYL PROGRAMMING LANGUAGE
▶ RECORDS IN FUNCTIONS
Using Records in Functions
Consider this program:
location { long -71.33 lat -37.42 }
go:
print location
set 85.78 28.35
print location
set long lat:
location.long long
location.lat lat
{
 long: -71.33
 lat: -37.42
}
{
 long: 85.78
 lat: 28.35
}
In set function, location record is set by long and lat parameters.

Passing a key to resetkey function:
location { long -71.33 lat -37.42 }
go:
print location
resetkey 'lat'
print location
resetkey key: location key 0
{
 long: -71.33
 lat: -37.42
}
{
 long: -71.33
 lat: 0
}
In line resetkey 'lat', we pass the key to the resetkey function, that will set the value of lat key to 0.

And to reset all keys of location record:
location { long -71.33 lat -37.42 }
go:
print location
reset
print location
reset: location k v ~ location k 0
{
 long: -71.33
 lat: -37.42
}
{
 long: 0
 lat: 0
}
Line location k v ~ location k 0, is a record iterator statement that iterates over all of record properties and sets their value to 0.

A record can be passed as a parameter to a function:
go:
location { long -71.33 lat -37.42 }
show location
show rec:
temp { long 0 lat 0 }
temp rec
print temp.long
print temp.lat
-71.33
-37.42
show function has rec parameter. To use rec parameter as a record parameter it is needed to assign it to local or global record, optionally with some or all of the source record properties declared.
In line temp rec, temp is assigned the mapping data of rec parameter. So upon calling show with location record, it is assigned to temp.

Note that a record parameter is a pass by value variable, and changing it inside the function will not alter the argument.

And to summerize this chapter, here is a full records in funtions functionality:
antuco { long -71.33 lat -37.42 }
immute antuco
location { long 0 lat 0 }
go:
    reset
    set antuco.long antuco.lat
    invert
    show location
    addkv 'height' 2953
    invert
    show location
resetkey key: location key 0
reset: location k v ~ location k 0
show rec:
temp { }
temp rec
temp k v ~ print k + ' = ' + v
print
set long lat:
location.long long
location.lat lat
setkv key val: location key val
addkv key val: location <- key val
invert:
long ( location.long > 0 ? location.long - 180 \ location.long + 180 )
lat ( location.lat > 0 ? location.lat - 180 \ location.lat + 180 )
set long lat
long = 108.67
lat = 142.58

long = -71.33
lat = -37.42
height = 2953
PART 7