LifeLines Programmers Reference

Version 3.0.2

up | previous | next | Tom Wetmore | ttw@shore.net | LifeLines


Language Overview

Contents


Procedures and Functions

A LifeLines program is made up of one or more procedures and functions (and global data declarations). A procedure has format:

  proc name ( params ) { statements }

Name is the name of the procedure, params is an optional list of parameters separated by commas, and statements is a list of statements that make up the procedure body. Program execution begins with the first statement in the procedure named main. Procedures may call other procedures and functions. Procedures are called with the call statement. When a procedure is called, the statements making up its body are executed.

A function has format:

  func name ( params ) { statements }

Name, params and statements are defined as in procedures. Functions may call other procedures and functions. When a function is called the statements that make it up are executed. A function differs from a procedure by returning a value to the procedure or function that calls it. Values are returned by the return statement. Recursive functions are allowed. A function is called by invoking it in an expression.


Comments

You may comment your LifeLines programs using the following notation:

  /*...comment text including any characters except */... */

Comments begin with a /* and end with a */. Comments may appear on lines of their own or on lines that have program constructs. Comments may span many lines. Comments may not be nested.


Statements

The programming language has a number of statement types. The simplest is an expression statement, an expression that is not part of any other statement or expression. An expression statement is evaluated, and if its value is non-zero, it is assumed to be a string, and written to the program output file. If its value is zero, nothing is written. For example, the expression name(indi), where indi is a person, returns the person's name and writes it to the output file. On the other hand, the expression set(n, nspouses(indi)) assigns the variable n the number of spouses that person indi has, but since set returns zero, nothing is written.

The programming language includes if statements, while statements and procedure call statements, with the following formats:

  if ([varb,] expr) { statements }
     [ elsif ([varb], expr) { statements } ]*
     [ else { statements } ]
     
  while ([varb,] expr ) { statements }
  
  call name ( args )

Square brackets indicate optional parts of the statement syntax. An if statement is executed by first evaluating the conditional expression in the if clause. If non-zero, the statements in the if clause are evaluated, and the rest of the if statement, if any, is ignored. If the value is zero, and there is an elsif clause following, the conditional in the elsif clause is evaluated, and if non-zero, the statements in that clause are executed. Conditionals are evaluated until one of them is non-zero, or until there are no more. If no conditional is non-zero, and if the if statement ends with an else clause, the statements in the else clause are executed. There are two forms of conditional expressions. If the conditional is a single expression, it is simply evaluated. If the conditional is a variable followed by an expression, the expression is evaluated and its value is assigned to the variable.

The while statement provides a looping mechanism. The conditional is evaluated, and if non-zero, the body of the loop is executed. After each iteration the expression is reevaluated; as long as it remains non-zero, the loop is repeated.

The call statement provides procedure calls. Name must match one of the procedures defined in the program. Args is a list of argument expressions separated by commas. Recursion is allowed. When a call is executed, the values of its arguments are evaluated and used to initialize the procedure's parameters. The procedure is then executed. When the procedure completes, execution resumes with the first item after the call.

The report language also includes the following statement types:

  include(string)
  global(varb)
  set(varb, expr)
  continue()
  break()
  return([expr])

The include statement includes the contents of another program file into the current file; its argument is the name of a LifeLines file. When an include statement is encountered, the file it refers to is read and treated as if the contents of the included file had been in the body of the original file at that point. This allows you to create LifeLines program library files that can be used by many programs. Included files may contain include statements, and so on to any depth. LifeLines will use the LLPROGRAMS shell variable, if set, to search for the include files.

The global statement must be used outside the scope of any procedure or function; it declares a variable to have global scope. The set statement is the assignment statement; the expression is evaluated, and its value is assigned to the variable. The continue statement jumps to the bottom of the current loop, but does not exit the loop. The break statement breaks out of the most closely nested loop. The return statement returns from the current procedure or function. Procedures have return statements without expressions; functions have return statements with expressions. None of these statements return a value, so none has a direct effect on program output.

In addition to these conventional statements, the report generator provides other iterator statements for looping through genealogical and other types of data. For example, the children statement iterates through the children of a family, the spouses statement iterates through the spouses of a person, and the families statement iterates through the families that a person is a spouse or parent in. These iterators and others are described in more detail later under the appropriate data types.


Expressions

There are four types of expressions: literals, integers, variables and built-in or user defined function calls.

A literal is any string enclosed in double quotes; its value is itself. An integer is any integer constant; its value is itself. A variable is a named location that can be assigned different values during program execution. The value of a variable is the last value assigned to it. Variables do not have fixed type; at different times in a program, the same variable may be assigned data of completely different types. An identifier followed by comma-separated list of expressions enclosed in parentheses, is either a call to a built-in function or a call to a user-defined function.


up | previous | next | Tom Wetmore | ttw@shore.net | LifeLines

1/1/00