Wafl Home

List Tutorial

Functions forall and exists

Functions forall(l,cond) i exists(l,cond) check if all/some list elements satisfy given condition.

Function forall is almost equivalent to

forall(l,f) = l->map(f)->aggregate(operator &&, true);

Function exists is equivalent to

exists(l,f) = l->map(f)->aggregate(operator ||, false);

The difference between library implementations and presented approach is in the library functions property to stop the processing if the result is already determined. Thus, exists stops the list element processing after the first element satisfying the condition is found, while forall stops the list element processing after the first element not satisfying the condition is found.

Source code:

{#
[1,2,3]->forall( operator>(_,1)),
[1,2,3]->forall( operator>=(_,1)),
[1,2,3]->exists( operator>(_,1)),
[1,2,3]->exists( operator<(_,1))
#}

Result:

{# false, true, true, false #}

 

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.