The BoaG Programming Guide - User-Defined Functions

While BoaG 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:

id := function(arg1: arg1Type, arg2: arg2Type, ..) [ : retType ] { body [ return retVal; ] };

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.

IsEmptyTitle := function(p: Paper): bool { if (p.metadata.title != “”) return true; return false; };

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.