Wafl Home

List Tutorial

Function filter

Function filter(l,cond) computes the list of elements of l that satisfy given condition. The element order is preserved.

Function forall is equivalent to

filter(l,cond) =
	if l->empty() then []
	else if l->hd()->cond() then l->hd():l->tl()->filter(cond)
	else l->tl()->filter(cond);

Source code:

{#
[1,2,3,4,5]->filter( operator>(_,1)),
[1,2,3,4,5]->filter( \x : x%2>0 ),	// even numbers
[1,2,3,4,5]->filter( \x : x%2=0 )	// odd numbers
#}

Result:

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

 

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.