Functions are used to define processes that are repeatedly performed
A structure can not be modified after its declaration, but its definition can be extended (overloading).
A function is defined is one of the following ways:
(1) [name]([parameters]):[process]
(2) [name]([parameters]):[process]
(3) [name]{[return structure]}([parameters]):[process]
(4) {[return structure]}([parameters]){[process]}
Where if the name is provided (1-3), then the function is stored as a signature. In (2) and (3), the function can be overloaded. Overloading can only be performed on the same types of functions, i.e. (2) can only overload (2).
The name of a function signature can not be in use for purposes other than the function signature.
(4) creates a function that can be stored in a variable, allowing the variable to change functions, but the variable must only store functions of the same signature.
If a function has a return statement in its process, then its return will be the value of the return or void, otherwise its value will be the body of the function
(1) creates a function that is defined purely on functionality. It has inferred arguments. This type of function can not have overloads, as it is supposed to represent a general functionality.
(2) creates a function that performs a process. Parameters can have types and default values. Overloading is based on parameters.
(3) creates a function that performs a process and returns a value. Parameters and arguments can have types and default values. Overloading is based on parameters and arguments.
(4) creates a function that is treated as a value. Parameters and return structure must have types. No overloading.
//definition of tally with (1)
//*note: these braces are for fields
tally(x){completed=0}: completed += x#;
//definition of till with (2)
till(land{field}):
for strip in land:
till(strip)
;
till(strip{field strip}):
tally(strip)
;
//...
//...
//definition of harvest with (3)
harvest{count=0}(items=[produce]):
for item in items: count += item#
;
harvest{count=0}(item=produce): count = produce#;
harvest{count=0;products=set}(items=[produce]):
for item in items: {
count, products += item#, item name;
}
;
//...
//...
//use of definition (4)
activity =
if season == fall: {int}(farm_data=farm){return harvest(farm_data crops)}
else season == winter: {int}(farm_data=farm){return maintain(farm_data barn)}
else season == spring: {int}(farm_data=farm){return plant(farm_data crops)}
else season == summer: {int}(farm_data=farm){return rest(farm_data farmhouse)}
a(Joes records)