Wafl Home

List Tutorial

List Processing

List elements are usually processed using recursion. The terminal condition is the list emptiness. If the list is not empty, usually the first element of the list is processed, and the computation of the rest of the list is performed by recursive application of the same function.

In the following example, the function incList(l) computes a list containing elements of list l increased by 1.

Function sumList(l) computes the sum of elements of the list of integers.

Function mkList(n,m) computes the list of all integers from the range [n,m].

Source code:

{#
[1,2,3]->incList(),
[1,2,3]->sumList(),
mkList(1,5),
mkList(1,100)->sumList()
#}
where{
    incList(l) =
        if l->empty() then []
        else (l->hd() + 1):l->tl()->incList();
    
    sumList(l) =
        if empty(l) then 0
        else l->hd() + l->tl()->sumList();

    mkList(n,m) =
    	if n <= m then n : mkList(n+1,m)
    	else [];
}

Result:

{# [2,3,4], 6, [1,2,3,4,5], 5050 #}

 

Table of Contents

Let's Start

Program Structure

Primitive Data Types

List

Tuple

Record

HTML

Command Line Interpreter

Using Web Servers

Syntax

Examples

Tips

The most of examples evaluates with both command line and Web server Wafl interpreters. If any example is based on specific features of an interpreter, it is explicitly annotated.