TYL PROGRAMMING LANGUAGE
▶ USING LISTS IN FUNCTIONS
Using Lists in Functions
Defining a list parameter:
average items:
items parameter will be a list parameter throughout average function.

List parameter must be in plural ending format.

List parameter is masking all other variables with the same name in the containing function, as well as all global variables. So in this code:
items [ 1 2 ]
print howmuch items
howmuch items:
items [ 10 ]
len items
1
items parameter of howmuch gets the global items list variable of the module. The line items [ 10 ], will not be a declaration line, nor an assignment to the global items, but a list assignment of the list value [ 10 ] into items parameter, and the result of howmuch is then 1.

List parameter is passed by reference:
data [ 1 2 ]
print data
cleardata data
print data
cleardata items: items ->->
[ 1, 2 ]
[ ]
Upon calling cleardata with data, items in cleardata will reference data, therefore line 'items ->->', will cause data to be cleared, as seen in the results.

If you do want to change a function list parameter without affecting the argument that was passed to the function, you should assign the parameter to another list variable:
data [ 1 2 6 -1 5 9 12 -3 10 ]
analyseddata [ ]
print data
analyse data
print analyseddata
analyse items:
analyseddata items
max len items
i max ~
  item items i
  item < 0 ? analyseddata i 0 \ item > 10 ? analyseddata i 10
^
[ 1, 2, 6, -1, 5, 9, 12, -3, 10 ]
[ 1, 2, 6, 0, 5, 9, 10, 0, 10 ]
PART 3