The BoaC Programming Guide - User-Defined Functions
While BoaC strives to provide useful domain-specific types and functions for performing analysis on research papers, anticipating all specific user needs is not feasible. This is why the language provides the ability for users to define their own functions. In this section, we outline the syntax for defining functions and demonstrate with a small example.
The general form of a user-defined function is given below:
Functions usually are assigned to variables. This is how the function can later be called. Functions declare the arguments and their types, the function's return type (if any), and provide a body for the function. The body returns values, if the function declares a return type.
As an example, imagine we want a function that takes a Paper
and determines if any papers have blank
'title
'. If at least one such paper exists in the
Paper
, we return true
. Otherwise we return
false
. The function IsEmptyTitle
below implements
this functionality.
This function is assigned to the IsEmptyTitle
variable. It
declares one argument named p
of type Paper
. It
also declares the return type of the function to be bool
.